From 03d9fee46ed8f5f5fa402b95152490a5a0367e15 Mon Sep 17 00:00:00 2001 From: Norihiro Kamae Date: Wed, 9 Oct 2024 00:33:47 +0900 Subject: [PATCH] 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. --- shared/opts-parser/opts-parser.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared/opts-parser/opts-parser.c b/shared/opts-parser/opts-parser.c index b9d3c4d55..063b7182e 100644 --- a/shared/opts-parser/opts-parser.c +++ b/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));