瀏覽代碼

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 16 年之前
父節點
當前提交
0f828dfbca
共有 1 個文件被更改,包括 9 次插入6 次删除
  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;
 	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 */
-		tmp.s++;
-		tmp.len--;
 		if (e->type == EVENT_DIALOG) {
 			pclass = CLASS_EVENT_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");
 			return -1;
 		}
-	} else {
-		e->params.list = NULL;
 	}
-
 	return 0;
 }