diff mbox

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

Message ID 1418128896-4222-1-git-send-email-naszar@ya.ru
State New
Headers show

Commit Message

Vladimir A. Nazarenko Dec. 9, 2014, 12:41 p.m. UTC
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 (__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.
---
 misc/mntent_r.c   |  6 +++++-
 misc/tst-mntent.c | 22 +++++++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

Comments

H.J. Lu Jan. 6, 2015, 5:11 p.m. UTC | #1
On Tue, Dec 9, 2014 at 4:41 AM, Vladimir A. Nazarenko <naszar@ya.ru> wrote:
> 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 (__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.
> ---
>  misc/mntent_r.c   |  6 +++++-
>  misc/tst-mntent.c | 22 +++++++++++++++++++++-
>  2 files changed, 26 insertions(+), 2 deletions(-)
>
> 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.  */
> 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;
>  }
> --
> 2.1.1
>

Has the copyright assignment issue been resolved?
Vladimir A. Nazarenko Jan. 6, 2015, 10:54 p.m. UTC | #2
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?
Joseph Myers Jan. 7, 2015, 12:04 a.m. UTC | #3
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.
diff mbox

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.  */
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;
 }