From 2f912c05dbebabb0446cf54e605d5d0f1bdc512c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 5 Sep 2022 11:55:55 +0200 Subject: lib: parse_area_spec: guard against NULL pointer dereference If mem_parse_options is called with an optstr containing x, but with swab == NULL, we will end up doing a NULL pointer dereference. Add a check that avoids this from happening. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220905095557.596891-31-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- lib/misc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/misc.c b/lib/misc.c index 532f0bfc1e..2d5f7c1985 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -159,6 +159,8 @@ int mem_parse_options(int argc, char *argv[], char *optstr, int *mode, *destfile = optarg; break; case 'x': + if (!swab) + return -EINVAL; *swab = 1; break; default: -- cgit v1.2.3