mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] mntent: exclude trailing newline from parsed field
@ 2024-10-19 18:13 Alyssa Ross
  0 siblings, 0 replies; only message in thread
From: Alyssa Ross @ 2024-10-19 18:13 UTC (permalink / raw)
  To: musl

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 ("mntent: fields are delimited only by tabs or spaces, not general whitespace")
---
The mntent tests I wrote for libc-test never got applied, but would 
have caught this regression.  I'll resend those.

 src/misc/mntent.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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);

base-commit: dd1e63c3638d5f9afb857fccf6ce1415ca5f1b8b
-- 
2.46.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-10-19 18:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-19 18:13 [musl] [PATCH] mntent: exclude trailing newline from parsed field Alyssa Ross

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).