From 0d512179c5e33de51620973250c9e3acf18ad082 Mon Sep 17 00:00:00 2001 From: Harshit Sharma Date: Tue, 26 May 2020 00:29:53 +0530 Subject: payloads/libpayload/libc: Avoid NULL pointer dereference Avoid dereferencing a NULL pointer in case of function parameter 'ptr'. Signed-off-by: Harshit Sharma Change-Id: I5dba27d9757fb55476f3d5848f0ed26ae9494bee Reviewed-on: https://review.coreboot.org/c/coreboot/+/41698 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- payloads/libpayload/libc/string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index c05a012f51..a481fef7eb 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -599,8 +599,6 @@ char *strtok_r(char *str, const char *delim, char **ptr) return start; } -static char **strtok_global; - /** * Extract first token in string str that is delimited by a character in tokens. * Destroys str, eliminates the token delimiter and uses global state. @@ -610,7 +608,9 @@ static char **strtok_global; */ char *strtok(char *str, const char *delim) { - return strtok_r(str, delim, strtok_global); + static char *strtok_ptr; + + return strtok_r(str, delim, &strtok_ptr); } /** -- cgit v1.2.3