Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 1 | From e4582c11f76b9390a3e172dcf0741dca90a9dc8d Mon Sep 17 00:00:00 2001 |
Brad Bishop | e42b3e3 | 2020-01-15 22:08:42 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Sat, 30 Nov 2019 18:50:34 -0800 |
| 4 | Subject: [PATCH] Do not use getsubopt |
| 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 | Simply avoid getsubopt, since we cannot rely on it. |
| 10 | |
| 11 | Imported from Alpine Linux |
| 12 | |
| 13 | Upstream-Status: Pending |
| 14 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 15 | |
Brad Bishop | e42b3e3 | 2020-01-15 22:08:42 -0500 | [diff] [blame] | 16 | --- |
| 17 | utils/v4l2-ctl/v4l2-ctl-common.cpp | 18 ++++++++++-------- |
| 18 | 1 file changed, 10 insertions(+), 8 deletions(-) |
| 19 | |
| 20 | diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 21 | index c940171..49c0f39 100644 |
Brad Bishop | e42b3e3 | 2020-01-15 22:08:42 -0500 | [diff] [blame] | 22 | --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp |
| 23 | +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 24 | @@ -956,15 +956,17 @@ static bool parse_subset(char *optarg) |
Brad Bishop | e42b3e3 | 2020-01-15 22:08:42 -0500 | [diff] [blame] | 25 | |
| 26 | static bool parse_next_subopt(char **subs, char **value) |
| 27 | { |
| 28 | - static char *const subopts[] = { |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 29 | - nullptr |
Brad Bishop | e42b3e3 | 2020-01-15 22:08:42 -0500 | [diff] [blame] | 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) |