Bug 17273 - getmntent() returns wrong default value for fs_passno
Summary: getmntent() returns wrong default value for fs_passno
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 18887
  Show dependency treegraph
 
Reported: 2014-08-15 03:52 UTC by naszar
Modified: 2015-08-29 22:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
simple test program (208 bytes, text/x-csrc)
2014-08-15 03:52 UTC, naszar
Details
test fstab (56 bytes, text/plain)
2014-08-15 03:53 UTC, naszar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description naszar 2014-08-15 03:52:43 UTC
Created attachment 7747 [details]
simple test program

man 5 fstab states that if the fifth field (fs_freq) and the sixth field (fs_passno) is not present a value of zero is returned (i.q. fs_req=0,fs_passno=0 if there is no fifth and sixth field in /etc/fstab  line). If fourth field ends with '\n' all work fine. But if there is extra tabs or spaces getmntent() returns garbage in ((struct mntent *) mp)->mnt_passno. It is because in misc/mntent_r.c:__getmntent_r() at line 167 no checks that sscanf() returns EOF or no striping for spaces and tabs like it done at line 164 for example.
In my mashine attached test_mntent (for testtab which also attached) say:
mnt_dir=/home	mnt_freq=42	mnt_passno=666
mnt_dir=/home	mnt_freq=42	mnt_passno=666
but must:
mnt_dir=/home	mnt_freq=42	mnt_passno=666
mnt_dir=/home	mnt_freq=0	mnt_passno=0
Comment 1 naszar 2014-08-15 03:53:38 UTC
Created attachment 7748 [details]
test fstab
Comment 3 Sourceware Commits 2015-08-29 22:10:55 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  b0e805fa0d6fea33745952df7b7f5442ca4c374f (commit)
      from  30da407eca459329e060d0412c3fa6710f657e83 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b0e805fa0d6fea33745952df7b7f5442ca4c374f

commit b0e805fa0d6fea33745952df7b7f5442ca4c374f
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Fri Aug 28 17:08:49 2015 -0400

    getmntent: fix memory corruption w/blank lines [BZ #18887]
    
    The fix for BZ #17273 introduced a single byte of memory corruption when
    the line is entirely blank.  It would walk back past the start of the
    buffer if the heap happened to be 0x20 or 0x09 and then write a NUL byte.
    	buffer = '\n';
    	end_ptr = buffer;
    	while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')
    		end_ptr--;
    	*end_ptr = '\0';
    
    Fix that and rework the tests.  Adding the testcase for BZ #17273 to the
    existing \040 parser does not really make sense as it's unrelated, and
    leads to confusing behavior: it implicitly relies on the new entry being
    longer than the previous entry (since it just rewinds the FILE*).  Split
    it out into its own dedicated testcase instead.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                          |   10 +++++
 misc/Makefile                                      |    3 +-
 misc/mntent_r.c                                    |    4 +-
 .../tst-mntent-blank-corrupt.c                     |   43 ++++++++-----------
 .../tst-mntent-blank-passno.c                      |   40 ++++++++++--------
 misc/tst-mntent.c                                  |   20 ---------
 6 files changed, 55 insertions(+), 65 deletions(-)
 copy posix/bug-regex35.c => misc/tst-mntent-blank-corrupt.c (60%)
 copy math/tst-definitions.c => misc/tst-mntent-blank-passno.c (55%)
Comment 4 Sourceware Commits 2015-08-29 22:13:31 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, release/2.21/master has been updated
       via  f2cdbadd8a078482d3b9fc2b59e888c64cc4efae (commit)
      from  978908245b2c0f759100708a9966649f7b273664 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f2cdbadd8a078482d3b9fc2b59e888c64cc4efae

commit f2cdbadd8a078482d3b9fc2b59e888c64cc4efae
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Fri Aug 28 17:08:49 2015 -0400

    getmntent: fix memory corruption w/blank lines [BZ #18887]
    
    The fix for BZ #17273 introduced a single byte of memory corruption when
    the line is entirely blank.  It would walk back past the start of the
    buffer if the heap happened to be 0x20 or 0x09 and then write a NUL byte.
    	buffer = '\n';
    	end_ptr = buffer;
    	while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')
    		end_ptr--;
    	*end_ptr = '\0';
    
    Fix that and rework the tests.  Adding the testcase for BZ #17273 to the
    existing \040 parser does not really make sense as it's unrelated, and
    leads to confusing behavior: it implicitly relies on the new entry being
    longer than the previous entry (since it just rewinds the FILE*).  Split
    it out into its own dedicated testcase instead.
    
    (cherry picked from commit b0e805fa0d6fea33745952df7b7f5442ca4c374f)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                          |   10 +++++
 NEWS                                               |    2 +-
 misc/Makefile                                      |    3 +-
 misc/mntent_r.c                                    |    4 +-
 .../tst-mntent-blank-corrupt.c                     |   27 +++++++------
 .../tst-mntent-blank-passno.c                      |   40 +++++++++++---------
 misc/tst-mntent.c                                  |   20 ----------
 7 files changed, 53 insertions(+), 53 deletions(-)
 copy libio/test-fmemopen.c => misc/tst-mntent-blank-corrupt.c (60%)
 copy math/tst-definitions.c => misc/tst-mntent-blank-passno.c (55%)
Comment 5 Sourceware Commits 2015-08-29 22:16:05 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, release/2.22/master has been updated
       via  3007f797a1a596e954f44879a5a7267966186ba4 (commit)
      from  64c25345714d792b283c8c8469d58f898d1ef109 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3007f797a1a596e954f44879a5a7267966186ba4

commit 3007f797a1a596e954f44879a5a7267966186ba4
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Fri Aug 28 17:08:49 2015 -0400

    getmntent: fix memory corruption w/blank lines [BZ #18887]
    
    The fix for BZ #17273 introduced a single byte of memory corruption when
    the line is entirely blank.  It would walk back past the start of the
    buffer if the heap happened to be 0x20 or 0x09 and then write a NUL byte.
    	buffer = '\n';
    	end_ptr = buffer;
    	while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')
    		end_ptr--;
    	*end_ptr = '\0';
    
    Fix that and rework the tests.  Adding the testcase for BZ #17273 to the
    existing \040 parser does not really make sense as it's unrelated, and
    leads to confusing behavior: it implicitly relies on the new entry being
    longer than the previous entry (since it just rewinds the FILE*).  Split
    it out into its own dedicated testcase instead.
    
    (cherry picked from commit b0e805fa0d6fea33745952df7b7f5442ca4c374f)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                          |   10 +++++
 NEWS                                               |    2 +-
 misc/Makefile                                      |    3 +-
 misc/mntent_r.c                                    |    4 +-
 .../tst-mntent-blank-corrupt.c                     |   43 ++++++++-----------
 .../tst-mntent-blank-passno.c                      |   40 ++++++++++--------
 misc/tst-mntent.c                                  |   20 ---------
 7 files changed, 56 insertions(+), 66 deletions(-)
 copy posix/bug-regex35.c => misc/tst-mntent-blank-corrupt.c (60%)
 copy math/tst-definitions.c => misc/tst-mntent-blank-passno.c (55%)
Comment 6 Sourceware Commits 2015-08-29 22:20:53 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, gentoo/2.21 has been updated
       via  460e5da421067eb690ba3b9d11183c4b7db37e4f (commit)
      from  43d7ce9238c59c61003994cb26eff4a6a072ebd5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=460e5da421067eb690ba3b9d11183c4b7db37e4f

commit 460e5da421067eb690ba3b9d11183c4b7db37e4f
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Fri Aug 28 17:08:49 2015 -0400

    getmntent: fix memory corruption w/blank lines [BZ #18887]
    
    The fix for BZ #17273 introduced a single byte of memory corruption when
    the line is entirely blank.  It would walk back past the start of the
    buffer if the heap happened to be 0x20 or 0x09 and then write a NUL byte.
    	buffer = '\n';
    	end_ptr = buffer;
    	while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')
    		end_ptr--;
    	*end_ptr = '\0';
    
    Fix that and rework the tests.  Adding the testcase for BZ #17273 to the
    existing \040 parser does not really make sense as it's unrelated, and
    leads to confusing behavior: it implicitly relies on the new entry being
    longer than the previous entry (since it just rewinds the FILE*).  Split
    it out into its own dedicated testcase instead.
    
    (cherry picked from commit b0e805fa0d6fea33745952df7b7f5442ca4c374f)
    (cherry picked from commit f2cdbadd8a078482d3b9fc2b59e888c64cc4efae)

-----------------------------------------------------------------------

Summary of changes:
 misc/Makefile                                      |    3 +-
 misc/mntent_r.c                                    |    4 +-
 .../tst-mntent-blank-corrupt.c                     |   27 +++++++------
 .../tst-mntent-blank-passno.c                      |   40 +++++++++++---------
 misc/tst-mntent.c                                  |   20 ----------
 5 files changed, 42 insertions(+), 52 deletions(-)
 copy libio/test-fmemopen.c => misc/tst-mntent-blank-corrupt.c (60%)
 copy math/tst-definitions.c => misc/tst-mntent-blank-passno.c (55%)
Comment 7 Sourceware Commits 2015-08-29 22:21:08 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, gentoo/2.22 has been updated
       via  ca6a9ce6151759981cc2efd58e053148c7db2fea (commit)
      from  0acbb93ebb8cf2a646cc2b685cd13b22d52f1e27 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ca6a9ce6151759981cc2efd58e053148c7db2fea

commit ca6a9ce6151759981cc2efd58e053148c7db2fea
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Fri Aug 28 17:08:49 2015 -0400

    getmntent: fix memory corruption w/blank lines [BZ #18887]
    
    The fix for BZ #17273 introduced a single byte of memory corruption when
    the line is entirely blank.  It would walk back past the start of the
    buffer if the heap happened to be 0x20 or 0x09 and then write a NUL byte.
    	buffer = '\n';
    	end_ptr = buffer;
    	while (end_ptr[-1] == ' ' || end_ptr[-1] == '\t')
    		end_ptr--;
    	*end_ptr = '\0';
    
    Fix that and rework the tests.  Adding the testcase for BZ #17273 to the
    existing \040 parser does not really make sense as it's unrelated, and
    leads to confusing behavior: it implicitly relies on the new entry being
    longer than the previous entry (since it just rewinds the FILE*).  Split
    it out into its own dedicated testcase instead.
    
    (cherry picked from commit b0e805fa0d6fea33745952df7b7f5442ca4c374f)
    (cherry picked from commit 3007f797a1a596e954f44879a5a7267966186ba4)

-----------------------------------------------------------------------

Summary of changes:
 misc/Makefile                                      |    3 +-
 misc/mntent_r.c                                    |    4 +-
 .../tst-mntent-blank-corrupt.c                     |   43 ++++++++-----------
 .../tst-mntent-blank-passno.c                      |   40 ++++++++++--------
 misc/tst-mntent.c                                  |   20 ---------
 5 files changed, 45 insertions(+), 65 deletions(-)
 copy posix/bug-regex35.c => misc/tst-mntent-blank-corrupt.c (60%)
 copy math/tst-definitions.c => misc/tst-mntent-blank-passno.c (55%)