From c044201472dc83f0c079b552473d4178e5fe4067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Fri, 5 Apr 2024 17:44:43 +0200 Subject: [PATCH] [FREELDR] Skip NULL-pointer entries in Argv when enumerating arguments. A NULL pointer (not necessarily the terminating one) is a valid entry in the Argv argument vector, according to the ARC specification (Section 4.4 "Loaded-Program Conventions"). Thus, such pointer needs to be ignored when searching over the argument vector. --- boot/freeldr/freeldr/lib/arcsupp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/boot/freeldr/freeldr/lib/arcsupp.c b/boot/freeldr/freeldr/lib/arcsupp.c index 1e3d7ecf180..af2b967a17f 100644 --- a/boot/freeldr/freeldr/lib/arcsupp.c +++ b/boot/freeldr/freeldr/lib/arcsupp.c @@ -23,9 +23,10 @@ GetNextArgumentValue( for (i = (LastIndex ? *LastIndex : 0); i < Argc; ++i) { - if (strlen(Argv[i]) >= ArgNameLen + 1 /* Count the '=' sign */ && - _strnicmp(Argv[i], ArgumentName, ArgNameLen) == 0 && - Argv[i][ArgNameLen] == '=') + if (Argv[i] /* NULL pointer is a valid entry in Argv: skip it */ && + (strlen(Argv[i]) >= ArgNameLen + 1 /* Count the '=' sign */) && + (_strnicmp(Argv[i], ArgumentName, ArgNameLen) == 0) && + (Argv[i][ArgNameLen] == '=')) { /* Found it, return the value */ if (LastIndex) *LastIndex = i;