[BZ,17273] fix incorrect mount table entry parsing in __getmntent_r()

Message ID 1409319124-31716-1-git-send-email-naszar@ya.ru
State Superseded
Headers

Commit Message

Vladimir A. Nazarenko Aug. 29, 2014, 1:32 p.m. UTC
  From: naszar <naszar@ya.ru>

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.

	[BZ 17273]
	*misc/mntent_r.c: fix incorrect mount table entry parsing
---
 misc/mntent_r.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Roland McGrath Aug. 29, 2014, 9:58 p.m. UTC | #1
Please write a test case.

> 	[BZ 17273]
> 	*misc/mntent_r.c: fix incorrect mount table entry parsing

This should look like:

	[BZ #17273]
	* misc/mntent_r.c (__getmntent_r): ...

and the actual text should be specific about how it changes the behavior.
  

Patch

diff --git a/misc/mntent_r.c b/misc/mntent_r.c
index e68ec8e..e0a0b9d 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.  */