Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From f7a4b79b3323534460a63b3e6c58ebaf06adf207 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 14 Jul 2017 13:20:05 -0700 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 4 | Subject: [PATCH] v4l2-ctl: Do not use getsubopt |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | |
| 6 | POSIX says that behavior when subopts list is empty is undefined. |
| 7 | musl libs will set value to NULL which leads to crash. |
| 8 | |
| 9 | Taken from AlpineLinux |
| 10 | |
| 11 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 12 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | --- |
| 14 | utils/v4l2-ctl/v4l2-ctl-common.cpp | 19 ++++++++++--------- |
| 15 | 1 file changed, 10 insertions(+), 9 deletions(-) |
| 16 | |
| 17 | diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp |
| 18 | index 3ea6cd3..291fb3e 100644 |
| 19 | --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp |
| 20 | +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp |
| 21 | @@ -692,16 +692,17 @@ static bool parse_subset(char *optarg) |
| 22 | |
| 23 | static bool parse_next_subopt(char **subs, char **value) |
| 24 | { |
| 25 | - static char *const subopts[] = { |
| 26 | - NULL |
| 27 | - }; |
| 28 | - int opt = getsubopt(subs, subopts, value); |
| 29 | + char *p = *subs; |
| 30 | + *value = *subs; |
| 31 | |
| 32 | - if (opt < 0 || *value) |
| 33 | - return false; |
| 34 | - fprintf(stderr, "No value given to suboption <%s>\n", |
| 35 | - subopts[opt]); |
| 36 | - return true; |
| 37 | + while (*p && *p != ',') |
| 38 | + p++; |
| 39 | + |
| 40 | + if (*p) |
| 41 | + *p++ = '\0'; |
| 42 | + |
| 43 | + *subs = p; |
| 44 | + return false; |
| 45 | } |
| 46 | |
| 47 | void common_cmd(int ch, char *optarg) |