Use vim_strchr(s, c) when c may be NUL (#6656)

As part of the refactoring in #5119, some vim_strchr() were changed to
strchr().  However, vim_strchr() behaves differently than strchr() when
c is NUL, returning NULL instead of a pointer to the NUL.

Revert the strchr() calls where it isn't known whether c is NUL, since
this causes a semantic change the surrounding code doesn't expect.  In
the case of #6650, this led to a heap overrun.

Closes #6650
This commit is contained in:
James McCoy
2017-05-03 04:12:38 -04:00
committed by Justin M. Keyes
parent 08b23d0806
commit de50c003d5
4 changed files with 27 additions and 5 deletions

View File

@@ -2687,7 +2687,7 @@ const char * set_one_cmd_context(
// 2. skip comment lines and leading space, colons or bars
const char *cmd;
for (cmd = buff; strchr(" \t:|", *cmd) != NULL; cmd++) {
for (cmd = buff; vim_strchr((const char_u *)" \t:|", *cmd) != NULL; cmd++) {
}
xp->xp_pattern = (char_u *)cmd;
@@ -2748,7 +2748,7 @@ const char * set_one_cmd_context(
}
}
// check for non-alpha command
if (p == cmd && strchr("@*!=><&~#", *p) != NULL) {
if (p == cmd && vim_strchr((const char_u *)"@*!=><&~#", *p) != NULL) {
p++;
}
len = (size_t)(p - cmd);
@@ -2779,7 +2779,7 @@ const char * set_one_cmd_context(
return NULL;
if (ea.cmdidx == CMD_SIZE) {
if (*cmd == 's' && strchr("cgriI", cmd[1]) != NULL) {
if (*cmd == 's' && vim_strchr((const char_u *)"cgriI", cmd[1]) != NULL) {
ea.cmdidx = CMD_substitute;
p = cmd + 1;
} else if (cmd[0] >= 'A' && cmd[0] <= 'Z') {