From patchwork Wed Jan 7 03:52:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 4537 Received: (qmail 27634 invoked by alias); 7 Jan 2015 03:52:45 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 27621 invoked by uid 89); 7 Jan 2015 03:52:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ob0-f170.google.com MIME-Version: 1.0 X-Received: by 10.60.137.161 with SMTP id qj1mr542806oeb.13.1420602760851; Tue, 06 Jan 2015 19:52:40 -0800 (PST) In-Reply-To: References: <1418128896-4222-1-git-send-email-naszar@ya.ru> <54AC67AC.6080700@ya.ru> Date: Tue, 6 Jan 2015 19:52:40 -0800 Message-ID: Subject: Re: [PATCH v3] [BZ #17273] fix incorrect mount table entry parsing in __getmntent_r() From: "H.J. Lu" To: Joseph Myers Cc: "Vladimir A. Nazarenko" , "GNU C . Library" , Roland McGrath On Tue, Jan 6, 2015 at 4:04 PM, Joseph Myers wrote: > On Wed, 7 Jan 2015, Vladimir A. Nazarenko wrote: > >> On 07.01.2015 03:11, H.J. Lu wrote: >> > >> > Has the copyright assignment issue been resolved? >> > >> >> Yes, I think so. I received signed paper from FSF. Should I send it to >> someone? > > I can confirm there is a copyright.list entry for Vladimir A. Nazarenko > dated 2014-11-24, so no further action is needed there. > This is what I checked in. Thanks. From fb87ee96d7dd0714d52004e4676629f8d9db732f Mon Sep 17 00:00:00 2001 From: "Vladimir A. Nazarenko" Date: Tue, 6 Jan 2015 19:19:44 -0800 Subject: [PATCH] Fix incorrect mount table entry parsing in __getmntent_r When mount entry contains only four fields and have more then one space or tab at the and, mp.mnt_freq and mp.mnt_passno will be set to some specific values as side effect from parsing of previus mount entry. It is because sscanf(""," %d %d ", &a, &b) returns -1, but this case is unprocessed. Values of mp.mnt_freq and mp.mnt_passno stays unchanged. This patch is attempt to fix described issue by removing trailing tabs and spaces. --- ChangeLog | 8 ++++++++ NEWS | 14 +++++++------- misc/mntent_r.c | 6 +++++- misc/tst-mntent.c | 22 +++++++++++++++++++++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b5aa6e5..9ca4f27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-01-06 Vladimir A. Nazarenko + +. [BZ #17273] + * misc/mntent_r.c (__getmntent_r): Cut off trailing spaces + and tabs from buffer before parsing fstab entry. + * misc/tst-mntent.c (main): Add test for mount entry with + trailing spaces and tabs. + 2015-01-06 Joseph Myers [BZ #17748] diff --git a/NEWS b/NEWS index acb611a..8582885 100644 --- a/NEWS +++ b/NEWS @@ -11,13 +11,13 @@ Version 2.21 6652, 10672, 12847, 12926, 13862, 14132, 14138, 14171, 14498, 15215, 15884, 16191, 16469, 16617, 16619, 16657, 16740, 16857, 17192, 17266, - 17344, 17363, 17370, 17371, 17411, 17460, 17475, 17485, 17501, 17506, - 17508, 17522, 17555, 17570, 17571, 17572, 17573, 17574, 17581, 17582, - 17583, 17584, 17585, 17589, 17594, 17601, 17608, 17616, 17625, 17630, - 17633, 17634, 17635, 17647, 17653, 17657, 17664, 17665, 17668, 17682, - 17717, 17719, 17722, 17723, 17724, 17725, 17732, 17733, 17744, 17745, - 17746, 17747, 17775, 17777, 17780, 17781, 17782, 17793, 17796, 17797, - 17806 + 17273, 17344, 17363, 17370, 17371, 17411, 17460, 17475, 17485, 17501, + 17506, 17508, 17522, 17555, 17570, 17571, 17572, 17573, 17574, 17581, + 17582, 17583, 17584, 17585, 17589, 17594, 17601, 17608, 17616, 17625, + 17630, 17633, 17634, 17635, 17647, 17653, 17657, 17664, 17665, 17668, + 17682, 17717, 17719, 17722, 17723, 17724, 17725, 17732, 17733, 17744, + 17745, 17746, 17747, 17775, 17777, 17780, 17781, 17782, 17793, 17796, + 17797, 17806 * i386 memcpy functions optimized with SSE2 unaligned load/store. diff --git a/misc/mntent_r.c b/misc/mntent_r.c index 152a9a2..6159873 100644 --- a/misc/mntent_r.c +++ b/misc/mntent_r.c @@ -135,7 +135,11 @@ __getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz) end_ptr = strchr (buffer, '\n'); if (end_ptr != NULL) /* chop newline */ - *end_ptr = '\0'; + { + while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t') + end_ptr--; + *end_ptr = '\0'; + } else { /* Not the whole line was read. Do it now but forget it. */ diff --git a/misc/tst-mntent.c b/misc/tst-mntent.c index 802b56e..876c89f 100644 --- a/misc/tst-mntent.c +++ b/misc/tst-mntent.c @@ -73,7 +73,27 @@ main (int argc, char *argv[]) puts ("Error while reading written entry back in"); result = 1; } - } + + /* Part III: Entry with whitespaces at the end of a line. */ + rewind (fp); + + fputs ("/foo\\040dir /bar\\040dir auto bind \t \n", fp); + + rewind (fp); + + mnt = getmntent (fp); + + if (strcmp (mnt->mnt_fsname, "/foo dir") != 0 + || strcmp (mnt->mnt_dir, "/bar dir") != 0 + || strcmp (mnt->mnt_type, "auto") != 0 + || strcmp (mnt->mnt_opts, "bind") != 0 + || mnt->mnt_freq != 0 + || mnt->mnt_passno != 0) + { + puts ("Error while reading entry with trailing whitespaces"); + result = 1; + } + } return result; } -- 1.9.3