From: Sam Moore Date: Mon, 19 Aug 2013 13:19:47 +0000 (+0800) Subject: Fix SensorHandler while loop X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=82a411cede82ee10a9d29dc08ca01949576ede24;p=matches%2FMCTX3420.git Fix SensorHandler while loop do while causes undefined behaviour when params string is empty --- diff --git a/server/fastcgi.c b/server/fastcgi.c index 1b758a4..d6e8079 100644 --- a/server/fastcgi.c +++ b/server/fastcgi.c @@ -76,9 +76,8 @@ static void SensorHandler(void * data, char * params) int sensor_id = SENSOR_NONE; - do + while ((params = FCGI_KeyPair(params, &key, &value)) != NULL) { - params = FCGI_KeyPair(params, &key, &value); Log(LOGDEBUG, "Got key=%s and value=%s", key, value); if (strcmp(key, "id") == 0) { @@ -104,14 +103,13 @@ static void SensorHandler(void * data, char * params) break; } } - while (params != NULL && *params != '\0'); - + if (sensor_id == SENSOR_NONE) { Log(LOGERR, "No sensor id specified"); status = STATUS_BADREQUEST; } - if (sensor_id >= NUMSENSORS || sensor_id < 0) + else if (sensor_id >= NUMSENSORS || sensor_id < 0) { Log(LOGERR, "Invalid sensor id %d", sensor_id); status = STATUS_BADREQUEST;