1From e4582c11f76b9390a3e172dcf0741dca90a9dc8d Mon Sep 17 00:00:00 2001 2From: Khem Raj <raj.khem@gmail.com> 3Date: Sat, 30 Nov 2019 18:50:34 -0800 4Subject: [PATCH] Do not use getsubopt 5 6POSIX says that behavior when subopts list is empty is undefined. 7musl libs will set value to NULL which leads to crash. 8 9Simply avoid getsubopt, since we cannot rely on it. 10 11Imported from Alpine Linux 12 13Upstream-Status: Pending 14Signed-off-by: Khem Raj <raj.khem@gmail.com> 15 16--- 17 utils/v4l2-ctl/v4l2-ctl-common.cpp | 18 ++++++++++-------- 18 1 file changed, 10 insertions(+), 8 deletions(-) 19 20diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp 21index c940171..49c0f39 100644 22--- a/utils/v4l2-ctl/v4l2-ctl-common.cpp 23+++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp 24@@ -956,15 +956,17 @@ static bool parse_subset(char *optarg) 25 26 static bool parse_next_subopt(char **subs, char **value) 27 { 28- static char *const subopts[] = { 29- nullptr 30- }; 31- int opt = getsubopt(subs, subopts, value); 32+ char *p = *subs; 33+ *value = *subs; 34 35- if (opt < 0 || *value) 36- return false; 37- fprintf(stderr, "Missing suboption value\n"); 38- return true; 39+ while (*p && *p != ',') 40+ p++; 41+ 42+ if (*p) 43+ *p++ = '\0'; 44+ 45+ *subs = p; 46+ return false; 47 } 48 49 void common_cmd(const std::string &media_bus_info, int ch, char *optarg) 50