util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Uzel <petr.uzel@suse.cz>
To: util-linux <util-linux@vger.kernel.org>
Subject: [PATCH 2/3] libmount: fix read before allocated buffer
Date: Thu, 14 Jun 2012 16:13:02 +0200	[thread overview]
Message-ID: <1339683183-21804-2-git-send-email-petr.uzel@suse.cz> (raw)
In-Reply-To: <1339683183-21804-1-git-send-email-petr.uzel@suse.cz>

valgrind --leak-check=full ./sys-utils/mount -t cifs //127.0.0.1/users /mnt/smb -o user=root,password=linux
....
==21359== Invalid read of size 1
==21359==    at 0x415AC6: mnt_optstr_remove_option_at (optstr.c:310)
==21359==    by 0x416358: mnt_optstr_apply_flags (optstr.c:716)
==21359==    by 0x40DFBF: mnt_context_prepare_mount (context_mount.c:86)
==21359==    by 0x40EB5A: mnt_context_mount (context_mount.c:782)
==21359==    by 0x4058B0: main (mount.c:918)
==21359==  Address 0x51cd5bf is 1 bytes before a block of size 10 alloc'd
==21359==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x4C29957: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x415780: __mnt_optstr_append_option (optstr.c:188)
==21359==    by 0x412822: mnt_fs_append_options (fs.c:764)
==21359==    by 0x409288: mnt_context_append_options (context.c:733)
==21359==    by 0x4053F0: main (mount.c:776)

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 libmount/src/optstr.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
index c8beada..2c9dd5e 100644
--- a/libmount/src/optstr.c
+++ b/libmount/src/optstr.c
@@ -307,7 +307,7 @@ int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end)
 	sz = strlen(end);
 
 	memmove(begin, end, sz + 1);
-	if (!*begin && *(begin - 1) == ',')
+	if (!*begin && (begin > *optstr) && *(begin - 1) == ',')
 		*(begin - 1) = '\0';
 
 	return 0;
-- 
1.7.7


  reply	other threads:[~2012-06-14 14:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-14 14:13 [PATCH 1/3] libmount: plug a memory leak in exec_helper() Petr Uzel
2012-06-14 14:13 ` Petr Uzel [this message]
2012-06-15  9:54   ` [PATCH 2/3] libmount: fix read before allocated buffer Karel Zak
2012-06-14 14:13 ` [PATCH 3/3] libmount: fix trivial typos Petr Uzel
2012-06-15  9:54   ` Karel Zak
2012-06-15  9:53 ` [PATCH 1/3] libmount: plug a memory leak in exec_helper() Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1339683183-21804-2-git-send-email-petr.uzel@suse.cz \
    --to=petr.uzel@suse.cz \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).