summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-04-02 07:42:06 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2022-04-02 07:42:06 -0400
commit43abe2d820d6725a9e8a248233539a6ffdc2d712 (patch)
tree3b87402a28a9d82985b872f93e39136f25fe1c2d
parent98f762316f0b065e9e4ce0ed8027eb0cc378eb32 (diff)
downloadrockbox-43abe2d820d6725a9e8a248233539a6ffdc2d712.tar.gz
rockbox-43abe2d820d6725a9e8a248233539a6ffdc2d712.zip
lastfm_scrobbler check pointers for validity
we need to make sure we don't deref NULL pointers Change-Id: I9c564b681cd20222c3a134680e60a310b2eb846c
-rw-r--r--apps/plugins/lastfm_scrobbler.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/apps/plugins/lastfm_scrobbler.c b/apps/plugins/lastfm_scrobbler.c
index 02a6bedd9f..7f424d8aca 100644
--- a/apps/plugins/lastfm_scrobbler.c
+++ b/apps/plugins/lastfm_scrobbler.c
@@ -317,6 +317,11 @@ static void scrobbler_flush_callback(void)
}
#endif
+static inline char* str_chk_valid(char *s, char *alt)
+{
+ return (s != NULL ? s : alt);
+}
+
static void scrobbler_add_to_cache(const struct mp3entry *id)
{
if ( gCache.pos >= SCROBBLER_MAX_CACHE )
@@ -335,17 +340,19 @@ static void scrobbler_add_to_cache(const struct mp3entry *id)
if (id->tracknum > 0)
rb->snprintf(tracknum, sizeof (tracknum), "%d", id->tracknum);
+ char* artist = id->artist ? id->artist : id->albumartist;
+
int ret = rb->snprintf(&scrobbler_buf[(SCROBBLER_CACHE_LEN*gCache.pos)],
SCROBBLER_CACHE_LEN,
"%s\t%s\t%s\t%s\t%d\t%c\t%ld\t%s\n",
- id->artist ? id->artist : id->albumartist,
- id->album,
- id->title,
+ str_chk_valid(artist, UNTAGGED),
+ str_chk_valid(id->album, ""),
+ str_chk_valid(id->title, ""),
tracknum,
(int)(id->length / 1000),
rating,
get_timestamp(),
- id->mb_track_id);
+ str_chk_valid(id->mb_track_id, ""));
if ( ret >= SCROBBLER_CACHE_LEN )
{