From 6bd95089f9d4be71313b7a0611f8233695c2b26f Mon Sep 17 00:00:00 2001 From: tonton th Date: Sat, 19 Dec 2020 12:49:06 +0100 Subject: [PATCH] fix a segfault in parse_filter_chain --- Fonderie/filterstack.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Fonderie/filterstack.c b/Fonderie/filterstack.c index 2ea9fdc6..07c8fa76 100644 --- a/Fonderie/filterstack.c +++ b/Fonderie/filterstack.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "../floatimg.h" #include "crapulator.h" @@ -165,7 +166,7 @@ return -1; /* -------------------------------------------------------------- */ int parse_filter_chain(int numid, char *argument) { -char *cptr; +char *cptr, *tmparg; int value, foo; if (numid < 0 || numid > NUMBER_OF_STACK) { @@ -181,11 +182,19 @@ if (foo) { return foo; } +/* BUG ? + If the 'argument' string is coming from a default value (as defined + here in main), strtok make a nice segfault. so I make a copy of that + string... +*/ +tmparg = alloca(strlen(argument) + 1); +strcpy(tmparg, argument); + for (;;) { - cptr = strtok(argument, ":"); + cptr = strtok(tmparg, ":"); // fprintf(stderr, "cptr %p\n", cptr); if (NULL==cptr) break; - argument = NULL; + tmparg = NULL; /* for the next pass of strtok */ // fprintf(stderr, " parsing '%s'\n", cptr); if (1 == sscanf(cptr, "%d", &value)) { foo = filterstack_add(numid, value, 1, 1.0);