File 0003-Fix-the-faulty-check-of-parameters-in-server_c.c-con.patch of Package timidity
From 10a3a90dcb65211fa72cd8eac6c080227c415a80 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Wed, 30 May 2012 13:06:03 +0200
Subject: [PATCH 3/9] 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 <tiwai@suse.de>
---
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 196ea7d..1b8b483 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;
}
--
1.7.9.2