Fix infinite loop in r_str_replace ##util

* Add check for empty `key`, since `r_str_replace` does not check for
  empty `key` and will loop indefinitely.
* Add test case for this (occurs with highlight grep)
This commit is contained in:
Richard Liu 2021-11-29 17:36:09 -06:00 committed by pancake
parent c5545c3d27
commit 1f123e41e4
2 changed files with 14 additions and 0 deletions

View File

@ -962,6 +962,9 @@ R_API char* r_str_replace(char *str, const char *key, const char *val, int g) {
r_str_replace_char (str, *key, *val);
return str;
}
if (klen == 0) {
return str;
}
if (klen == vlen && !strcmp (key, val)) {
return str;
}

View File

@ -438,3 +438,14 @@ Hello World
4e2420
EOF
RUN
NAME=highlight grep with empty string
ARGS=-escr.highlight.grep=true
TIMEOUT=2
CMDS=<<EOF
i~[0]:0
EOF
EXPECT=<<EOF
fd
EOF
RUN