string-util: make sure we eat even half complete words in split()

split() and FOREACH_WORD really should die, and everything be moved to
extract_first_word() and friends, but let's at least make sure that for
the remaining code using it we can't deadlock by not progressing in the
word iteration.

Fixes: #15305
This commit is contained in:
Lennart Poettering
2020-04-02 16:43:36 +02:00
parent 5fed82c642
commit 29965a2a6e
2 changed files with 8 additions and 3 deletions
+2 -3
View File
@@ -113,7 +113,7 @@ static size_t strcspn_escaped(const char *s, const char *reject) {
bool escaped = false;
int n;
for (n=0; s[n]; n++) {
for (n = 0; s[n] != '\0'; n++) {
if (escaped)
escaped = false;
else if (s[n] == '\\')
@@ -122,8 +122,7 @@ static size_t strcspn_escaped(const char *s, const char *reject) {
break;
}
/* if s ends in \, return index of previous char */
return n - escaped;
return n;
}
/* Split a string into words. */