[PATCH 30/32] lib: parse_area_spec: guard against NULL pointer dereference

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Sep 5 02:55:55 PDT 2022


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 <a.fatoum at pengutronix.de>
---
 lib/misc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/misc.c b/lib/misc.c
index 532f0bfc1eb5..2d5f7c198586 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:
-- 
2.30.2




More information about the barebox mailing list