From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8662 invoked from network); 23 Apr 2022 18:46:51 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 23 Apr 2022 18:46:51 -0000 Received: (qmail 18191 invoked by uid 550); 23 Apr 2022 18:46:47 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 18158 invoked from network); 23 Apr 2022 18:46:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=dIdmeGiQad7MHNp61sfvWKyGHhkB6k43iNkpaoZY0TI=; b=LPn91TevATI1yDYL0aUCZpm6A6OakOgCx9NM3Mm38KIdmQ2Qo6Vw22MvWwdVQt56a+ 0nd025y+QyqsDHyLaJdtheTzUQfYhTOxSBVMWdhKBKriRUsUx8XQ/tWrAUVAZwOXGyo+ lqCLKYDx48YZltpK0o1iKlANwMHji0BdfRXo554DoPFvifZtvaquipbDkNaq3C2qlIA0 gBLM3xQxuxx2aG8oo1sIj62xtJKHaLb4w0qmnOYpDOZsxcqR6O+7eGlluf6ZCq4ZRrgl 98JR+81HLJP7AlihtS0wr95CSYdwbmbdG+YDgCWZT5ULdrDBqcQ2qSLCa1tM/AgLaE96 tMcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=dIdmeGiQad7MHNp61sfvWKyGHhkB6k43iNkpaoZY0TI=; b=xKPKEqqa3aZsINwWOFicR5a3tQdqkHTccKBg25GNtK+TTiTipi8Xm0SE0pejNO28GF qEZ/L4LklrCEB/h5/WuDXu+oOweE8x9PvcEGj59d17A5O4zXWKi/VrQBRsQSikSV9CfQ qSNS60zuUHXY4H5hLn3hBI5xIwFos+xgk+ZDzY2Fr5XD6Jpc+5HEOZbSxUTQB/e9n8rx 0JCPNXiBr23E/sHeFRQI9Fo0L4BWI6b6GnYgIBFzgGngrNQdvHa58FzXYHgYnWSjJEqH 9ntZ6z/cnw7GdNWgXETEBPdWpxOHHmTiafz3ciJ4g5cmW7pYWm9UjXLBoW+rUmmD5ZPP mOpg== X-Gm-Message-State: AOAM531DHQ7E29W4lvp2LmGd30g0vtNOExXpLybbyc5SxfAyeqs4JsSV JGqgl3sR91HDkvZeABou7O6UeKxI9dKKdhY0jIhSqfHc X-Google-Smtp-Source: ABdhPJy5Zh1XVgXTFGjYPv+NQoYaDHUEvXoZucfekbPLYuzxPVNp27bHSA/1n9r1pRrWE1ZUqdZaSuz5MEqpHQ6y29E= X-Received: by 2002:aca:df03:0:b0:2ef:895e:7373 with SMTP id w3-20020acadf03000000b002ef895e7373mr4936016oig.177.1650739594862; Sat, 23 Apr 2022 11:46:34 -0700 (PDT) MIME-Version: 1.0 From: Oliver Ford Date: Sat, 23 Apr 2022 19:46:32 +0100 Message-ID: To: musl@lists.openwall.com Content-Type: multipart/alternative; boundary="0000000000002b235d05dd56c33b" Subject: [musl] [PATCH] getmntent_r: support empty source field --0000000000002b235d05dd56c33b Content-Type: text/plain; charset="UTF-8" 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 --0000000000002b235d05dd56c33b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Some mount types su= ch 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 fir= st does not match every field.

Issue originally ra= ised by=C2=A0Keyu Tao= on 6th April. As per discussion,
octal escape characters are not yet supported= but can be implemented
next.
---
=C2=A0src/misc/mnt= ent.c | 40 +++++++++++++++++++++++++++++-----------
=C2=A01 file = changed, 29 insertions(+), 11 deletions(-)

diff --= git a/src/misc/mntent.c b/src/misc/mntent.c
index eabb8200..43041= 881 100644
--- a/src/misc/mntent.c
+++ b/src/misc/mnten= t.c
@@ -21,7 +21,7 @@ int endmntent(FILE *f)
=C2=A0
=C2=A0struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *= linebuf, int buflen)
=C2=A0{
- int cnt, n[8], use_internal =3D (linebuf =3D=3D SENTINE= L);
+ int cnt, ch, n[= 8], use_internal =3D (linebuf =3D=3D SENTINEL);
=C2=A0
= =C2=A0 mnt->mnt_freq =3D 0;<= /div>
=C2=A0 mnt->mnt_pa= ssno =3D 0;
@@ -39,20 +39,38 @@ struct mntent *getmntent_r(FILE *= f, struct mntent *mnt, char *linebuf, int bufle
=C2=A0 errno =3D ERANGE;
=C2=A0 return 0;
=C2=A0 }
+
+ ch =3D strspn(linebuf, " ");
+ if (linebuf[ch] =3D= =3D '#') continue;
+
=C2=A0 cnt =3D sscanf(linebuf, " %n%*s%n %n%*s%n %n= %*s%n %n%*s%n %d %d",
=C2=A0 n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
=C2=A0 &mnt->mnt_freq, &mnt-&g= t;mnt_passno);
- } wh= ile (cnt < 2 || linebuf[n[0]] =3D=3D '#');
-
- linebuf[n[1]] =3D 0;
- linebuf[n[3]] =3D 0;
=
- linebuf[n[5]] =3D 0;
- linebuf[n[7]] =3D 0;
+ if (cnt =3D=3D 2) {=
+ linebuf[n[1]] = =3D 0;
+ linebuf[n[= 3]] =3D 0;
+ linebu= f[n[5]] =3D 0;
+ li= nebuf[n[7]] =3D 0;
+ mnt->mnt_fsname =3D linebuf+n[0];
+ mnt->mnt_dir =3D linebuf+n[2];
+ mnt->mnt_type =3D linebuf+n[4];
+ mnt->mnt_opts = =3D linebuf+n[6];
+ = } else {
+ cnt =3D = 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);
=C2=A0
- mnt->mnt_fsname =3D linebuf+n[0];
- mnt->mnt_dir =3D linebu= f+n[2];
- mnt->mnt= _type =3D linebuf+n[4];
- mnt->mnt_opts =3D linebuf+n[6];
+ if (cnt =3D=3D 2) {
+ linebuf[n[1]] =3D 0;
+ linebuf[n[3]] =3D 0;
+ linebuf[n[5]] =3D 0;
+ mnt->mnt_fsname =3D "&quo= t;;
+ mnt->mnt_= dir =3D linebuf+n[0];
+ <= /span>mnt->mnt_type =3D linebuf+n[2];
+ mnt->mnt_opts =3D linebuf+n[4];
+ }
+ }
+ } while (cnt < 2);
=C2=A0
=C2=A0 return mnt;
=C2=A0}
= --=C2=A0
2.35.1

--0000000000002b235d05dd56c33b--