mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
To: musl@lists.openwall.com
Cc: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Subject: [musl] [PATCH] fix error handling in getsubopt()
Date: Wed,  3 Nov 2021 13:47:57 +0100	[thread overview]
Message-ID: <20211103124757.15214-1-marian.buschsieweke@ovgu.de> (raw)

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


             reply	other threads:[~2021-11-03 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 12:47 Marian Buschsieweke [this message]
2021-11-03 13:20 ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211103124757.15214-1-marian.buschsieweke@ovgu.de \
    --to=marian.buschsieweke@ovgu.de \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).