[pseudo] [PATCH 1/7] pseudo.h: Avoid accessing unallocated memory

Richard Purdie <[email protected]> Wed, 1 Jul 2026 14:13:30 +0100
Newsgroups org.yoctoproject.lists.yocto-patches
Message-ID <[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]>
---
 pseudo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pseudo.h b/pseudo.h
index b6c13f2..1152c19 100644
--- a/pseudo.h
+++ b/pseudo.h
@@ -99,7 +99,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"