Commit 3327917f by Dwight Engen Committed by Serge Hallyn

fix potential out of bounds pointer deref

I noticed that if find_first_wholeword() is called with word at the very beginning of p, we will deref *(p - 1) to see if it is a word boundary. Fix by considering p = p0 to be a word boundary. Signed-off-by: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 9313e1e6
...@@ -1534,13 +1534,16 @@ static int is_word_sep(char c) ...@@ -1534,13 +1534,16 @@ static int is_word_sep(char c)
} }
} }
static const char *find_first_wholeword(const char *p, const char *word) static const char *find_first_wholeword(const char *p0, const char *word)
{ {
const char *p = p0;
if (!p) if (!p)
return NULL; return NULL;
while ((p = strstr(p, word)) != NULL) { while ((p = strstr(p, word)) != NULL) {
if (is_word_sep(*(p-1)) && is_word_sep(p[strlen(word)])) if ((p == p0 || is_word_sep(*(p-1))) &&
is_word_sep(p[strlen(word)]))
return p; return p;
p++; p++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment