summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2024-10-19 20:13:21 +0200
committerRich Felker <dalias@aerifal.cx>2024-10-22 17:44:52 -0400
commit4e6c827cf48aa4277033d3444e419cb435b0a68c (patch)
treed828068a2f2ccc895fb5cb7f3af6d74353e1dbd9 /src
parent9929a571b5b662c2ce106f1c08a9faf02af58d8a (diff)
downloadmusl-4e6c827cf48aa4277033d3444e419cb435b0a68c.tar.gz
mntent: exclude trailing newline from parsed field
When the pattern was changed from matching any whitespace to just matching spaces and tabs, a newline started being appended to the value of the matched field, if that field was a string. For example, in a 4-field line, the mnt_opts field would have a newline on the end. This happened because a newline is not a space or a tab, and so was matched as part of the value before the end of the string was reached. \n should therefore be added as a character that terminates a value. This shouldn't interfere with the intention of the change to space and tab only, as it was trying to make sure that other whitespace like carriage returns, that should have been part of parsed values, were. Fixes: f314e133
Diffstat (limited to 'src')
-rw-r--r--src/misc/mntent.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/misc/mntent.c b/src/misc/mntent.c
index 78bf0cd0..ee17a69f 100644
--- a/src/misc/mntent.c
+++ b/src/misc/mntent.c
@@ -81,7 +81,7 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle
len = strlen(linebuf);
if (len > INT_MAX) continue;
for (i = 0; i < sizeof n / sizeof *n; i++) n[i] = len;
- sscanf(linebuf, " %n%*[^ \t]%n %n%*[^ \t]%n %n%*[^ \t]%n %n%*[^ \t]%n %d %d",
+ sscanf(linebuf, " %n%*[^ \t\n]%n %n%*[^ \t\n]%n %n%*[^ \t\n]%n %n%*[^ \t\n]%n %d %d",
n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
&mnt->mnt_freq, &mnt->mnt_passno);
} while (linebuf[n[0]] == '#' || n[1]==len);