|
Message-ID: <CAGMVOduqaPzE4fGxx5_Reb1MUGaEKAkXD2beHzVZm0CwiYRFiw@mail.gmail.com>
Date: Sat, 23 Apr 2022 19:46:32 +0100
From: Oliver Ford <ojford@...il.com>
To: musl@...ts.openwall.com
Subject: [PATCH] getmntent_r: support empty source field
Some mount types such as tmpfs allow the source field
to be an empty string. Handle the case of an empty source
field with a second sscanf if the first does not match every field.
Issue originally raised by Keyu Tao on 6th April. As per discussion,
octal escape characters are not yet supported but can be implemented
next.
---
src/misc/mntent.c | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/src/misc/mntent.c b/src/misc/mntent.c
index eabb8200..43041881 100644
--- a/src/misc/mntent.c
+++ b/src/misc/mntent.c
@@ -21,7 +21,7 @@ int endmntent(FILE *f)
struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int
buflen)
{
- int cnt, n[8], use_internal = (linebuf == SENTINEL);
+ int cnt, ch, n[8], use_internal = (linebuf == SENTINEL);
mnt->mnt_freq = 0;
mnt->mnt_passno = 0;
@@ -39,20 +39,38 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt,
char *linebuf, int bufle
errno = ERANGE;
return 0;
}
+
+ ch = strspn(linebuf, " ");
+ if (linebuf[ch] == '#') continue;
+
cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%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 (cnt < 2 || linebuf[n[0]] == '#');
-
- linebuf[n[1]] = 0;
- linebuf[n[3]] = 0;
- linebuf[n[5]] = 0;
- linebuf[n[7]] = 0;
+ if (cnt == 2) {
+ linebuf[n[1]] = 0;
+ linebuf[n[3]] = 0;
+ linebuf[n[5]] = 0;
+ linebuf[n[7]] = 0;
+ mnt->mnt_fsname = linebuf+n[0];
+ mnt->mnt_dir = linebuf+n[2];
+ mnt->mnt_type = linebuf+n[4];
+ mnt->mnt_opts = linebuf+n[6];
+ } else {
+ cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %d %d",
+ n, n+1, n+2, n+3, n+4, n+5, n+6,
+ &mnt->mnt_freq, &mnt->mnt_passno);
- mnt->mnt_fsname = linebuf+n[0];
- mnt->mnt_dir = linebuf+n[2];
- mnt->mnt_type = linebuf+n[4];
- mnt->mnt_opts = linebuf+n[6];
+ if (cnt == 2) {
+ linebuf[n[1]] = 0;
+ linebuf[n[3]] = 0;
+ linebuf[n[5]] = 0;
+ mnt->mnt_fsname = "";
+ mnt->mnt_dir = linebuf+n[0];
+ mnt->mnt_type = linebuf+n[2];
+ mnt->mnt_opts = linebuf+n[4];
+ }
+ }
+ } while (cnt < 2);
return mnt;
}
--
2.35.1
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.