diff mbox series

[pseudo,15/23] pseudo.h: Avoid accessing unallocated memory

Message ID 1783039578-31531-16-git-send-email-mark.hatle@kernel.crashing.org
State New
Headers show
Series Create new pseudo 1.99.0 version | expand

Commit Message

Mark Hatle July 3, 2026, 12:46 a.m. UTC
From: Richard Purdie <richard.purdie@linuxfoundation.org>

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 <richard.purdie@linuxfoundation.org>
Message-ID: <20260701131336.3578279-1-richard.purdie@linuxfoundation.org>
Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
---
 pseudo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

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"