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_INVALID,DKIM_SIGNED, 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 31761 invoked from network); 15 Sep 2021 23:39:16 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 15 Sep 2021 23:39:16 -0000 Received: (qmail 21860 invoked by uid 550); 15 Sep 2021 23:39:06 -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 20352 invoked from network); 15 Sep 2021 22:12:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=CzBmRnWmnSq+L FGigi3DroRv4YjXJi5VqePdzIQRdtw=; b=wTwbLTG9TNRcMiTLqPulfJOhG7yTk dfrw6iZY8XwF1C8Kzl+Rm85qsClLeMXQjrZ6RaH1GxL+G0t8tq/uOEaG8xtyFoqr 4zG28kabO5whHG0u9A0Gn5KgL8nYcQNSxvLeBZwInv7DaTYrhoA6Jz9Pt924T1C9 rmjpJjeVKWHIU0ej0cV6fG/5bj3EtgQ3Vpin92c8MMiqcNqIhodvvY3II1EQ88d4 iQJ7j+GI3Tbb4J0SemflA/Ja76LYWLLJkSTiPtICEri1uja2htDUpaHxqe6SUclw tlHVPV9yeSqGpjDETaoU5Bruufwc6BaDb0BY3UjydQD6itaDCNUfiSf+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=CzBmRnWmnSq+LFGigi3DroRv4YjXJi5VqePdzIQRdtw=; b=Tbv5VDv4 01Q6iSUMiSWXJJO3ME59rfd6CBvO2yYzwz1wYXH/q8UTrGr4EErbeffRQIOGBN3N LowMcF50hHivJXYHNJIGIsH66N4i7dptMIk0+IyDxGEhk23Xt2mzQ2TUTpRwSD4k Wzpg2YGxPttf6hMiOC4FeZ5SXBokmYen1MihXZIImHue1D08MPmRsgzJ1et4Z8w9 DAwvz4mYLnkRl5TXrnsuCK35n0ssi5zsld1+VwDcHG7p25ONi+EPD9xQ4QhWOUTA FTXfFEfQko67/0nxsGsCRHG7BVw5eIBIzjMAUJygicfvTlFZxdFzNvvrd5ucdRC8 UInp2CwibamhxQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudehfedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheptehlhihsshgrucftohhsshcuoehhihesrghlhihsshgrrdhi sheqnecuggftrfgrthhtvghrnhepgfefudekvdelieelledufeevheeglefggedvudejvd dtffeuueevffehleejkedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomhepqhihlhhishhsseigvddvtddrqhihlhhishhsrdhnvght X-ME-Proxy: From: Alyssa Ross To: musl@lists.openwall.com Cc: =?UTF-8?q?=C3=89rico=20Nogueira?= , Rich Felker Date: Wed, 15 Sep 2021 22:11:55 +0000 Message-Id: <20210915221155.3977763-4-hi@alyssa.is> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210915221155.3977763-1-hi@alyssa.is> References: <20210915221155.3977763-1-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH musl v2 3/3] mntent: fix parsing lines with optional fields According to fstab(5), the last two fields are optional, but this wasn't accepted by Musl. After this change, only the first field is required, which matches Glibc's behaviour. Using sscanf as before, it would have been impossible to differentiate between 0 fields and 4 fields, because sscanf would have returned 0 in both cases due to the use of assignment suppression and %n for the string fields (which is important to avoid copying any strings). So instead, before calling sscanf, initialize every string to the empty string, and then we can check which strings are empty afterwards to know how many fields were matched. --- We could also be stricter about it, and enforce that the first four fields are present, since the man page says only the last two are optional. Doing that would be a simple change of checking for the presence of mnt_opts instead of mnt_fsname at the end of my patch. v2: don't change n from int to size_t src/misc/mntent.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/misc/mntent.c b/src/misc/mntent.c index eabb8200..238a0efd 100644 --- a/src/misc/mntent.c +++ b/src/misc/mntent.c @@ -21,7 +21,8 @@ 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 n[8], use_internal = (linebuf == SENTINEL); + size_t len, i; mnt->mnt_freq = 0; mnt->mnt_passno = 0; @@ -39,10 +40,14 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle errno = ERANGE; return 0; } - 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]] == '#'); + + len = strlen(linebuf); + for (i = 0; i < sizeof n / sizeof *n; i++) n[i] = len; + if (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) == EOF && ferror(f)) + return 0; + } while (linebuf[n[0]] == '#'); linebuf[n[1]] = 0; linebuf[n[3]] = 0; @@ -54,6 +60,9 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle mnt->mnt_type = linebuf+n[4]; mnt->mnt_opts = linebuf+n[6]; + if (!*mnt->mnt_fsname) + return 0; + return mnt; } -- 2.32.0