From: Adam Dickmeiss Date: Mon, 17 Aug 2015 12:38:01 +0000 (+0200) Subject: Fix yaz-client command args parsing broken YAZ-855 X-Git-Tag: v5.14.6~1 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=473f3071b86a40479e38e3fe4d434c0d2bf03379;p=yaz-moved-to-github.git Fix yaz-client command args parsing broken YAZ-855 Bug introduced in 5be87e7a04c7219b31cefc0a3 --- diff --git a/client/client.c b/client/client.c index 14ce06a..0d686ee 100644 --- a/client/client.c +++ b/client/client.c @@ -5184,27 +5184,31 @@ static int cmd_register_tab(const char* arg) static void process_cmd_line(char* line) { int i, res; - char word[32], arg[10240]; + char word[32], *arg; + int no_read = 0; #if HAVE_GETTIMEOFDAY gettimeofday(&tv_start, 0); #endif - if ((res = sscanf(line, "%31s %10239s", word, arg)) <= 0) + sscanf(line, "%31s%n", word, &no_read); + if (no_read == 0) { strcpy(word, last_cmd); - *arg = '\0'; + arg = line + strlen(line); } - else if (res == 1) - *arg = 0; + else + arg = line + no_read; strcpy(last_cmd, word); - /* removed tailing spaces from the arg command */ + /* whitespace chop */ { - char* p = arg; - char* lastnonspace=NULL; + char *p; + char *lastnonspace = 0; - for (; *p; ++p) + while (*arg && yaz_isspace(*arg)) + arg++; + for (p = arg; *p; ++p) { if (!yaz_isspace(*p)) lastnonspace = p; @@ -5288,9 +5292,9 @@ static char **readline_completer(char *text, int start, int end) } else { - char arg[10240],word[32]; - int i ,res; - if ((res = sscanf(rl_line_buffer, "%31s %10239s", word, arg)) <= 0) + char word[32]; + int i; + if (sscanf(rl_line_buffer, "%31s", word) <= 0) { rl_attempted_completion_over = 1; return NULL;