aboutsummaryrefslogtreecommitdiffstats
path: root/main/v4l-utils/getsubopt.patch
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2017-05-31 21:26:00 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2017-06-01 10:15:07 +0200
commitdfa7d220828b373c8d45ea627ea5b37dee28fcb7 (patch)
treeead37b34c834de44b36436c4cbfccf092235e7a5 /main/v4l-utils/getsubopt.patch
parent29edf549a07f9ef4d55cee0e9caf890df35d18b3 (diff)
downloadaports-dfa7d220828b373c8d45ea627ea5b37dee28fcb7.tar.bz2
aports-dfa7d220828b373c8d45ea627ea5b37dee28fcb7.tar.xz
main/v4l-utils: fix segfault due to undefined behavior in getsubopt
fixes #7047
Diffstat (limited to 'main/v4l-utils/getsubopt.patch')
-rw-r--r--main/v4l-utils/getsubopt.patch36
1 files changed, 36 insertions, 0 deletions
diff --git a/main/v4l-utils/getsubopt.patch b/main/v4l-utils/getsubopt.patch
new file mode 100644
index 0000000000..c476e5ed7e
--- /dev/null
+++ b/main/v4l-utils/getsubopt.patch
@@ -0,0 +1,36 @@
+POSIX says that behavior when subopts list is empty is undefined.
+musl libs will set value to NULL which leads to crash.
+
+Simply avoid getsubopt, since we cannot rely on it.
+
+diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp
+index 3ea6cd3..291fb3e 100644
+--- a/utils/v4l2-ctl/v4l2-ctl-common.cpp
++++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp
+@@ -692,16 +692,17 @@ static bool parse_subset(char *optarg)
+
+ static bool parse_next_subopt(char **subs, char **value)
+ {
+- static char *const subopts[] = {
+- NULL
+- };
+- int opt = getsubopt(subs, subopts, value);
++ char *p = *subs;
++ *value = *subs;
+
+- if (opt < 0 || *value)
+- return false;
+- fprintf(stderr, "No value given to suboption <%s>\n",
+- subopts[opt]);
+- return true;
++ while (*p && *p != ',')
++ p++;
++
++ if (*p)
++ *p++ = '\0';
++
++ *subs = p;
++ return false;
+ }
+
+ void common_cmd(int ch, char *optarg)