From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24435 invoked from network); 3 Nov 2021 12:48:31 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 3 Nov 2021 12:48:31 -0000 Received: (qmail 1329 invoked by uid 550); 3 Nov 2021 12:48:28 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 1294 invoked from network); 3 Nov 2021 12:48:27 -0000 From: Marian Buschsieweke To: musl@lists.openwall.com Cc: Marian Buschsieweke Date: Wed, 3 Nov 2021 13:47:57 +0100 Message-Id: <20211103124757.15214-1-marian.buschsieweke@ovgu.de> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] fix error handling in getsubopt() The man page of getsubopt says > int getsubopt(char **restrict optionp, char *const *restrict tokens, > char **restrict valuep); > > [...] > RETURN VALUE > If the first suboption in optionp is recognized, getsubopt() > returns the index of the matching suboption element in tokens. > Otherwise, -1 is returned and *valuep is the entire name[=value] > string. This means, *val should be set to the value *opt had upon the call of getsubopt on failure, but this is not the case. This fixes the behavior. This fixes a segmentation fault in the option parsing in v4l2-ctl for the -c parameter. (E.g. v4l2-ctl -c foo=bar will segfault without this.) --- src/misc/getsubopt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/misc/getsubopt.c b/src/misc/getsubopt.c index 53ee9573..37cca186 100644 --- a/src/misc/getsubopt.c +++ b/src/misc/getsubopt.c @@ -19,5 +19,6 @@ int getsubopt(char **opt, char *const *keys, char **val) else if (s[l]) continue; return i; } + *val = s; return -1; } -- 2.33.1