summaryrefslogtreecommitdiff
path: root/src/basic/string-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-04-02 16:36:33 +0200
committerLennart Poettering <lennart@poettering.net>2020-04-02 16:43:36 +0200
commit29965a2a6e22c9f369e70cffd9ff780d1c1d31a1 (patch)
tree24f897d8e836ef8bde1bc44e4798bd99495c86ad /src/basic/string-util.c
parent5fed82c642963f58de96ffc112935ced2d2a3ade (diff)
downloadsystemd-29965a2a6e22c9f369e70cffd9ff780d1c1d31a1.tar.gz
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
Diffstat (limited to 'src/basic/string-util.c')
-rw-r--r--src/basic/string-util.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index 2eb84babd8..9983aa826e 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -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. */