浏览代码

shared/opts-parser: Fix crash when no options were given to the parser

When passing just a space, the number of input options becomes 0. In
this case, calling `bmalloc` should be avoided.
Norihiro Kamae 1 年之前
父节点
当前提交
03d9fee46e
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      shared/opts-parser/opts-parser.c

+ 6 - 0
shared/opts-parser/opts-parser.c

@@ -34,6 +34,12 @@ struct obs_options obs_parse_options(const char *options_string)
 	size_t input_option_count = 0;
 	for (char **input_word = input_words; *input_word; ++input_word)
 		input_option_count += 1;
+
+	if (!input_option_count) {
+		strlist_free(input_words);
+		goto failure;
+	}
+
 	char **ignored_words = bmalloc(input_option_count * sizeof(*ignored_words));
 	char **ignored_word = ignored_words;
 	struct obs_option *out_options = bmalloc(input_option_count * sizeof(*out_options));