about summary refs log tree commit diff
path: root/misc/tst-mntent.c
diff options
context:
space:
mode:
authorVladimir A. Nazarenko <naszar@ya.ru>2015-01-06 19:19:44 -0800
committerH.J. Lu <hjl.tools@gmail.com>2015-01-06 19:51:01 -0800
commitfb87ee96d7dd0714d52004e4676629f8d9db732f (patch)
tree650a8563ae0ea966709d998aeb4391f81df4b87f /misc/tst-mntent.c
parent01238691bb03f0110455b663439eecf9a58c8f83 (diff)
downloadglibc-fb87ee96d7dd0714d52004e4676629f8d9db732f.tar.gz
glibc-fb87ee96d7dd0714d52004e4676629f8d9db732f.tar.xz
glibc-fb87ee96d7dd0714d52004e4676629f8d9db732f.zip
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.
Diffstat (limited to 'misc/tst-mntent.c')
-rw-r--r--misc/tst-mntent.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/misc/tst-mntent.c b/misc/tst-mntent.c
index 802b56e437..876c89f8ed 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;
 }