From e3d5b4fa77d7cf9b7e94cead5510cf2f6a75d04e Mon Sep 17 00:00:00 2001 From: Jocelyn Jaubert Date: Mon, 11 Oct 2010 21:38:05 +0200 Subject: [PATCH] Check that the mpd response to command outputs is correct before parsing it --- panel-plugin/simple-libmpd.c | 8 ++++++++ panel-plugin/simple-libmpd.h | 1 + 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/panel-plugin/simple-libmpd.c b/panel-plugin/simple-libmpd.c index 0084358..2bbdacd 100644 --- a/panel-plugin/simple-libmpd.c +++ b/panel-plugin/simple-libmpd.c @@ -448,6 +448,14 @@ void parse_outputs_answer(MpdObj *mo, void *param) while(lines[i] && md->alloutputs[md->nb]->enabled < 0) { tokens = g_strsplit(lines[i], ":", 2); + /* sanity check: verify that the string is correct */ + if (!tokens[0] || !tokens[1]) + { + fprintf(stderr, "xfce4-mpc-plugin: got an incorrect response from mpd!\n"); + fprintf(stderr, " ** command='%s', response='%s'\n", "outputs", mo->buffer); + mo->error = MPD_ERROR_RESPONSE; + return; + } /* remove leading whitespace */ tokens[1] = g_strchug(tokens[1]); DBG("key=\"%s\",value=\"%s\"", tokens[0], tokens[1]); diff --git a/panel-plugin/simple-libmpd.h b/panel-plugin/simple-libmpd.h index 405fd40..7dfa38e 100644 --- a/panel-plugin/simple-libmpd.h +++ b/panel-plugin/simple-libmpd.h @@ -38,6 +38,7 @@ #define MPD_ERROR_NORESPONSE 15 /* no response on attempting to connect */ #define MPD_ERROR_SENDING 16 /* error sending command */ #define MPD_ERROR_CONNCLOSED 17 /* connection closed by mpd */ +#define MPD_ERROR_RESPONSE 18 /* incorrect response */ typedef struct { -- 1.7.1