From 1f2b608d62a42ff95f03334f4eaf1556d507cb31 Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 26 Jan 2019 10:07:48 +0100 Subject: [PATCH 1/2] [mpd] Fix wrong number of format parameters for safe_asprintf Fixes a segfault in cases where the default playlist directory config (in the mpd section of the configuration file) was set/activated. --- src/mpd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mpd.c b/src/mpd.c index 25ae2cfe..c349045b 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -2267,7 +2267,7 @@ mpd_command_listplaylist(struct evbuffer *evbuf, int argc, char **argv, char **e else { // Argument is a playlist name, prepend default playlist directory - path = safe_asprintf("%s/%s%s", default_pl_dir, argv[1]); + path = safe_asprintf("%s/%s", default_pl_dir, argv[1]); } pli = db_pl_fetch_byvirtualpath(path); @@ -2330,7 +2330,7 @@ mpd_command_listplaylistinfo(struct evbuffer *evbuf, int argc, char **argv, char else { // Argument is a playlist name, prepend default playlist directory - path = safe_asprintf("%s/%s%s", default_pl_dir, argv[1]); + path = safe_asprintf("%s/%s", default_pl_dir, argv[1]); } pli = db_pl_fetch_byvirtualpath(path); @@ -2449,7 +2449,7 @@ mpd_command_load(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, s else { // Argument is a playlist name, prepend default playlist directory - path = safe_asprintf("%s/%s%s", default_pl_dir, argv[1]); + path = safe_asprintf("%s/%s", default_pl_dir, argv[1]); } pli = db_pl_fetch_byvirtualpath(path); @@ -3260,7 +3260,7 @@ mpd_sticker_set(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, co rating *= MPD_RATING_FACTOR; if (rating > DB_FILES_RATING_MAX) { - *errmsg = safe_asprintf("rating '%s' is greater than maximum value allowed", argv[5], (DB_FILES_RATING_MAX / MPD_RATING_FACTOR)); + *errmsg = safe_asprintf("rating '%s' is greater than maximum value allowed", argv[5]); return ACK_ERROR_ARG; } From b000803fe3ec89a9cb63294191d4783638cc0429 Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 26 Jan 2019 10:08:11 +0100 Subject: [PATCH 2/2] [misc] Add compiler hint to check format parameters --- src/misc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc.h b/src/misc.h index edc63c19..0fb6416f 100644 --- a/src/misc.h +++ b/src/misc.h @@ -56,10 +56,10 @@ char * safe_strdup(const char *str); char * -safe_asprintf(const char *fmt, ...); +safe_asprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); int -safe_snprintf_cat(char *dst, size_t n, const char *fmt, ...); +safe_snprintf_cat(char *dst, size_t n, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); /* Key/value functions */