Procházet zdrojové kódy

event parser: Add missing string boundary checks to event_parser func.

The function event_parser needs to check that there is still some text
left in the input string before it attempts to read the text.

In addition to that the function also needs to skip any possible
leading whitespace before it calls parse_params, because parse_params
expects that there is no leading whitespace at the beginning of the
input string.

Reported by Juha Heinanen
Jan Janak před 16 roky
rodič
revize
0f828dfbca
1 změnil soubory, kde provedl 9 přidání a 6 odebrání
  1. 9 6
      parser/parse_event.c

+ 9 - 6
parser/parse_event.c

@@ -117,10 +117,16 @@ int event_parser(char* s, int len, event_t* e)
 	tmp.s = end;
 	tmp.s = end;
 	trim_leading(&tmp);
 	trim_leading(&tmp);
 
 
-	if (tmp.s[0] == ';') {
+	e->params.list = NULL;
+	
+	if (tmp.len && (tmp.s[0] == ';')) {
+		/* Shift the semicolon and skip any leading whitespace, this is needed
+		 * for parse_params to work correctly. */
+		tmp.s++; tmp.len--;
+		trim_leading(&tmp);
+		if (!tmp.len) return 0;
+
 		/* We have parameters to parse */
 		/* We have parameters to parse */
-		tmp.s++;
-		tmp.len--;
 		if (e->type == EVENT_DIALOG) {
 		if (e->type == EVENT_DIALOG) {
 			pclass = CLASS_EVENT_DIALOG;
 			pclass = CLASS_EVENT_DIALOG;
 			phooks = (param_hooks_t*)&e->params.dialog;
 			phooks = (param_hooks_t*)&e->params.dialog;
@@ -130,10 +136,7 @@ int event_parser(char* s, int len, event_t* e)
 			ERR("event_parser: Error while parsing parameters parameters\n");
 			ERR("event_parser: Error while parsing parameters parameters\n");
 			return -1;
 			return -1;
 		}
 		}
-	} else {
-		e->params.list = NULL;
 	}
 	}
-
 	return 0;
 	return 0;
 }
 }