From 631fae8f9a1e22986d8c2beeb82295ad140d24c6 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Wed, 30 May 2012 15:22:35 +0200 Subject: [PATCH] Fix the faulty check of parameters in server_c.c:control_getcmd() The check of the array size in server_c.c:control_getcmd() is wrong as the nparmas is incremeted after the check with MAX_GETCMD_PARAMS. Also, there are other bugs that *nparams isn't initialized when the first token is NULL, etc. Overall, the code is unnecessarily tricky. This patch simplifies the code and fixes the array size check. Bugzila: https://bugzilla.novell.com/show_bug.cgi?id=517719 Signed-off-by: Takashi Iwai Signed-off-by: Hans de Goede --- interface/server_c.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/interface/server_c.c b/interface/server_c.c index 196ea7da..1b8b4838 100644 --- a/interface/server_c.c +++ b/interface/server_c.c @@ -525,11 +525,13 @@ static int control_getcmd(char **params, int *nparams) } if(n == 0) return 1; - if((params[0] = strtok(buff, " \t\r\n\240")) == NULL) - return 0; *nparams = 0; - while(params[*nparams] && *nparams < MAX_GETCMD_PARAMS) - params[++(*nparams)] = strtok(NULL," \t\r\n\240"); + do { + params[*nparams] = strtok(*nparams ? NULL : buff, " \t\r\n\240"); + if (!params[*nparams]) + break; + (*nparams)++; + } while (*nparams < MAX_GETCMD_PARAMS); return 0; } -- 2.11.0