From 3934bf4448a582b67b543cde83bbfe1ade4b0b11 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Mon, 22 Feb 2010 22:22:03 +0000 Subject: [PATCH] * Fix issue with playlists containing a single quote. * Ignore bad playlists containing binary data. --- playlist.c | 14 +++++++++----- tagutils/tagutils-plist.c | 22 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/playlist.c b/playlist.c index 85b394b..c0c5887 100644 --- a/playlist.c +++ b/playlist.c @@ -40,7 +40,7 @@ insert_playlist(const char * path, char * name) { struct song_metadata plist; struct stat file; - int items = 0, matches; + int items = 0, matches, ret; char type[4]; strncpy(type, strrchr(name, '.')+1, 4); @@ -50,11 +50,16 @@ insert_playlist(const char * path, char * name) DPRINTF(E_WARN, L_SCANNER, "Bad playlist [%s]\n", path); return -1; } - while( next_plist_track(&plist, &file, NULL, type) == 0 ) + while( (ret = next_plist_track(&plist, &file, NULL, type)) == 0 ) { items++; freetags(&plist); } + if( ret == 2 ) // Bad playlist -- contains binary characters + { + DPRINTF(E_WARN, L_SCANNER, "Bad playlist [%s]\n", path); + return -1; + } strip_ext(name); DPRINTF(E_DEBUG, L_SCANNER, "Playlist %s contains %d items\n", name, items); @@ -113,9 +118,8 @@ fill_playlists() continue; DPRINTF(E_DEBUG, L_SCANNER, "Scanning playlist \"%s\" [%s]\n", plname, plpath); - sprintf(sql_buf, "SELECT ID from OBJECTS where PARENT_ID = '"MUSIC_PLIST_ID"'" - " and NAME = '%s'", plname); - if( sql_get_int_field(db, sql_buf) <= 0 ) + if( sql_get_int_field(db, "SELECT ID from OBJECTS where PARENT_ID = '"MUSIC_PLIST_ID"'" + " and NAME = '%q'", plname) <= 0 ) { detailID = GetFolderMetadata(plname, NULL, NULL, NULL, NULL); sql_exec(db, "INSERT into OBJECTS" diff --git a/tagutils/tagutils-plist.c b/tagutils/tagutils-plist.c index 91d618a..3c0d2e6 100644 --- a/tagutils/tagutils-plist.c +++ b/tagutils/tagutils-plist.c @@ -50,14 +50,14 @@ start_plist(const char *path, struct song_metadata *psong, struct stat *stat, ch _utf8bom = 0; _trackno = 0; - if(strcmp(type, "m3u") == 0) + if(strcasecmp(type, "m3u") == 0) _next_track = _m3u_next_track; - else if(strcmp(type, "pls") == 0) + else if(strcasecmp(type, "pls") == 0) _next_track = _pls_next_track; if(!_next_track) { - DPRINTF(E_ERROR, L_SCANNER, "Unsupported playlist type <%s>\n", type); + DPRINTF(E_ERROR, L_SCANNER, "Unsupported playlist type <%s> (%s)\n", type, path); return -1; } @@ -118,6 +118,14 @@ _m3u_next_track(struct song_metadata *psong, struct stat *stat, char *lang, char while(p) { while(isspace(*p)) p++; + + if(!isprint(*p)) + { + DPRINTF(E_ERROR, L_SCANNER, "Playlist looks bad (unprintable characters)\n"); + fclose(fp); + return 2; + } + if(*p && *p != '#') { // check dos format @@ -153,6 +161,14 @@ _pls_next_track(struct song_metadata *psong, struct stat *stat, char *lang, char while(p) { while(isspace(*p)) p++; + + if(!isprint(*p)) + { + DPRINTF(E_ERROR, L_SCANNER, "Playlist looks bad (unprintable characters)\n"); + fclose(fp); + return 2; + } + if(*p && *p != '#') { // verify that it's a valid pls playlist