From f9483512435a754b98e108df7e91e2a401790fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kowalczyk?= Date: Tue, 7 Jul 2020 01:08:25 +0200 Subject: [PATCH] [Pal] Fix out-of-bounds read in strstartswith_static --- Pal/include/lib/api.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Pal/include/lib/api.h b/Pal/include/lib/api.h index fcc89152..e9bf444e 100644 --- a/Pal/include/lib/api.h +++ b/Pal/include/lib/api.h @@ -129,13 +129,15 @@ void *malloc(size_t size); void free(void *ptr); void *calloc(size_t nmemb, size_t size); -/* check if the var is exactly the same as the static string */ +/* check if `var` is exactly the same as a static string */ #define strcmp_static(var, str) \ (memcmp(var, str, MIN(strlen(var), static_strlen(str)) + 1)) -/* check if the var starts with the static string */ -#define strstartswith_static(var, str) \ - (!memcmp(var, str, static_strlen(str))) +/* check if `str` starts with a static string */ +#define strstartswith_static(str, prefix) \ + (strlen(str) >= static_strlen(prefix) \ + ? !memcmp(str, prefix, static_strlen(prefix)) \ + : false) /* copy static string and return the address of the NUL byte (NULL if the dest * is not large enough).*/