From 6e7e52de7afe29597016952a7317faf9c3ea3268 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sat, 30 Nov 2019 18:50:34 -0800
Subject: [PATCH] Do not use getsubopt

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.

Imported from Alpine Linux

Upstream-Status: Pending

Signed-off-by: Khem Raj <raj.khem@gmail.com>

Adapt patch to 1.23.0.

(v4l-utils rev fd544473800d02e90bc289434cc44e5aa8fadd0f).

%% original patch: 0007-Do-not-use-getsubopt.patch

Signed-off-by: Daniel Gomez <daniel@qtec.com>
---
 utils/v4l2-ctl/v4l2-ctl-common.cpp | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp
index d77f7104..838c297d 100644
--- a/utils/v4l2-ctl/v4l2-ctl-common.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp
@@ -994,15 +994,17 @@ static bool parse_subset(char *optarg)
 
 static bool parse_next_subopt(char **subs, char **value)
 {
-	static char *const subopts[] = {
-	    nullptr
-	};
-	int opt = v4l_getsubopt(subs, subopts, value);
+	char *p = *subs;
+	*value = *subs;
 
-	if (opt < 0 || *value)
-		return false;
-	fprintf(stderr, "Missing suboption value\n");
-	return true;
+	while (*p && *p != ',')
+		p++;
+
+	if (*p)
+		*p++ = '\0';
+
+	*subs = p;
+	return false;
 }
 
 void common_cmd(const std::string &media_bus_info, int ch, char *optarg)
-- 
2.35.1

