From f894e989509f8e484276ad6ec1fbbac238d78dd1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 14 Jan 2007 02:08:27 +0000 Subject: [PATCH] jack: fix potential segfaults in parsing bad configs for 'ports' git-svn-id: https://svn.musicpd.org/mpd/trunk@5251 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audioOutputs/audioOutput_jack.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index 186f3396f..c5eeab728 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -175,11 +175,27 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) if ( ! param ) return 0; if ( (bp = getBlockParam(param, "ports")) ) { - cp = xstrdup(bp->value); - ERROR("output_ports=%s\n", cp); - output_ports[0] = xstrdup(strtok (cp, ",")); - output_ports[1] = xstrdup(strtok (NULL, ",")); - free(cp); + DEBUG("output_ports=%s\n", bp->value); + + if (!(cp = strchr(bp->value, ','))) + FATAL("expected comma and a second value for '%s' " + "at line %d: %s\n", + bp->name, bp->line, bp->value); + + *cp = '\0'; + output_ports[0] = xstrdup(bp->value); + *cp++ = ','; + + if (!*cp) + FATAL("expected a second value for '%s' at line %d: " + "%s\n", bp->name, bp->line, bp->value); + + output_ports[1] = xstrdup(cp); + + if (strchr(cp,',')) + FATAL("Only %d values are supported for '%s' " + "at line %d\n", + ARRAY_SIZE(output_ports), bp->name, bp->line); } if ( (bp = getBlockParam(param, "ringbuffer_size")) ) {