From b61b0ba0b13a6c834b60a22df977c1b64d3b3292 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Thu, 6 Nov 2008 15:38:28 +0000 Subject: [PATCH] use memchr instead of strchr because the strign might not be NUL terminated. --- ChangeLog | 5 +++++ src/softmagic.c | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20ce0f2c..c2e2213a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-11-06 10:35 Christos Zoulas + + * use memchr instead of strchr because the string + might not be NUL terminated (Scott MacVicar) + 2008-10-30 11:00 Reuben Thomas * Correct words counts in comments of struct magic. diff --git a/src/softmagic.c b/src/softmagic.c index 3dff3c7e..0eec2fa3 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.125 2008/10/30 10:43:49 rrt Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.126 2008/11/04 16:38:28 christos Exp $") #endif /* lint */ #include "magic.h" @@ -806,6 +806,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, const char *c; const char *last; /* end of search region */ const char *buf; /* start of search region */ + const char *end; size_t lines; if (s == NULL) { @@ -814,10 +815,10 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, return 0; } buf = (const char *)s + offset; - last = (const char *)s + nbytes; + end = last = (const char *)s + nbytes; /* mget() guarantees buf <= last */ for (lines = linecnt, b = buf; - lines && ((b = strchr(c = b, '\n')) || (b = strchr(c, '\r'))); + lines && ((b = memchr(c = b, '\n', end - b)) || (b = memchr(c, '\r', end - c))); lines--, b++) { last = b; if (b[0] == '\r' && b[1] == '\n') -- 2.40.0