[pseudo][PATCH v2 15/23] pseudo.h: Avoid accessing unallocated memory
Mark Hatle <[email protected]> Fri, 3 Jul 2026 13:40:47 -0500
| Newsgroups | org.yoctoproject.lists.yocto-patches |
|---|---|
| Message-ID | <1783104055-19005-16-git-send-email-mark.hatle@kernel.crashing.org> |
From: Richard Purdie <[email protected]> We can call STARTSWITH in cases where the item being searched for is longer than the string itself. Switch from memcmp to strncmp to avoid accessing unassigned memory. Signed-off-by: Richard Purdie <[email protected]> Message-ID: <[email protected]> Signed-off-by: Mark Hatle <[email protected]> --- pseudo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pseudo.h b/pseudo.h index 66aa70e..ae1fe0d 100644 --- a/pseudo.h +++ b/pseudo.h @@ -119,7 +119,7 @@ extern char *pseudo_version; #define PSEUDO_LIBDIR "lib" #endif -#define STARTSWITH(x, y) (!memcmp((x), (y), sizeof(y) - 1)) +#define STARTSWITH(x, y) (strncmp(y, x, strlen(y)) == 0) #ifndef PSEUDO_LOCALSTATEDIR #define PSEUDO_LOCALSTATEDIR "var/pseudo" -- 1.8.3.1