From: Ben K <7563474-tracking-ng@users.noreply.gitlab.com> Date: Thu, 24 Aug 2023 08:54:38 +0000 (+0200) Subject: Fix htsstr_argsplit (treat quotes inside an argument correctly) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe4df311d1209ba86d514a34abc0b9c694d53b5f;p=thirdparty%2Ftvheadend.git Fix htsstr_argsplit (treat quotes inside an argument correctly) There seemed to be a flaw in the splitting logic when it comes to quotes, e.g.: --output="filename" should be one argument, but htsstr_argsplit treated it as ['--output=', '"filename"] which I think is wrong. I fixed this and added two tests for this scenario. --- diff --git a/src/htsstr.c b/src/htsstr.c index db66de3ad..35c10d0d3 100644 --- a/src/htsstr.c +++ b/src/htsstr.c @@ -133,6 +133,7 @@ htsstr_argsplit_add char ** htsstr_argsplit(const char *str) { int quote = 0; + int quote_inbetween = 0; // when quote isn't start of argument int inarg = 0; const char *start = NULL; const char *s; @@ -147,16 +148,19 @@ htsstr_argsplit(const char *str) { break; case '"': if(quote) { - inarg = 0; quote = 0; if (start) { htsstr_argsplit_add(&argv, &argc, start, s); start = NULL; } + } else if (quote_inbetween) { + quote_inbetween = 0; + } else { + quote_inbetween = 1; } break; case ' ': - if(quote) + if(quote||quote_inbetween) break; inarg = 0; if (start) { @@ -297,6 +301,8 @@ void main(int argc, char *argv[]) "sh -c \"/bin/df -P -h /recordings >/config/.markers/recording-pre-process\"", "bash -c '/bin/df -P -h /recordings >/config/.markers/recording-pre-process'", "bash -c \"/bin/df -P -h /recordings | tee /config/.markers/recording-pre-process\"", + "/bin/grep --label=\"TVHeadend Recording\" \"start time\"", + "/bin/grep --label=\"TVHeadend Recordings \"File \"start time\" /recordings", NULL, }; char **s = strings, **x;