util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Davidlohr Bueso <davidlohr@hp.com>
To: kzak@redhat.com
Cc: davidlohr@hp.com, aswin@hp.com, util-linux@vger.kernel.org
Subject: [PATCH 12/13] sfdisk: fix --unhide segfault
Date: Tue, 22 Jul 2014 16:44:56 -0700	[thread overview]
Message-ID: <1406072697-20912-13-git-send-email-davidlohr@hp.com> (raw)
In-Reply-To: <1406072697-20912-1-git-send-email-davidlohr@hp.com>

There's currently a NULL ptr dereference bug when calling asc_to_index()
via set_unhidden(). Fix this bug by checking the optarg value for null.
This is similar to how other options handle such calls.

Before:
Segmentation fault (core dumped)

After:
sfdisk: Done: Success

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
 disk-utils/sfdisk.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 86ed112..f730504 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -2909,12 +2909,13 @@ static int do_activate(char **av, int ac, char *arg)
 	return ret;
 }
 
-static void
-set_unhidden(struct disk_desc *z, char *pnam) {
+static void set_unhidden(struct disk_desc *z, char *pnam)
+{
 	int pno;
 	unsigned char id;
 
 	pno = asc_to_index(pnam, z);
+	printf("\t%s\n", pnam);
 	id = z->partitions[pno].p.sys_type;
 	if (id == 0x11 || id == 0x14 || id == 0x16 || id == 0x17 ||
 	    id == 0x17 || id == 0x1b || id == 0x1c || id == 0x1e)
@@ -2943,7 +2944,7 @@ static int do_unhide(char **av, int ac, char *arg)
 	get_partitions(dev, fd, z);
 
 	/* unhide where desired */
-	if (ac == 1)
+	if (ac == 1 && arg)
 		set_unhidden(z, arg);
 	else
 		for (i = 1; i < ac; i++)
-- 
1.8.1.4

  parent reply	other threads:[~2014-07-22 23:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-22 23:44 [PATCH 00/13] sfdisk: Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 01/13] sfdisk: remove bogus argc check Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 02/13] sfdisk: deprecate --linux option Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 03/13] sfdisk: remove dead code Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 04/13] sfdisk: remove 'short_opts' global variable Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 05/13] sfdisk: fix indentation Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 06/13] sfdisk: remove declaraion of 'partname()' Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 07/13] sfdisk: remove 'exit_status' global variable Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 08/13] sfdisk: move main function at the end of the file Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 09/13] fdisk: remove bugus space after header includes Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 10/13] sfdisk: update [embarrassingly] old man-page Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 11/13] sfdisk: rework option handling Davidlohr Bueso
2014-07-22 23:44 ` Davidlohr Bueso [this message]
2014-07-26  4:22   ` [PATCH 12/13] sfdisk: fix --unhide segfault Davidlohr Bueso
2014-07-22 23:44 ` [PATCH 13/13] sfdisk: activate_usage() can use noreturn attribute Signed-off-by: Davidlohr Bueso <davidlohr@hp.com> Davidlohr Bueso
2014-07-22 23:46 ` [PATCH 00/13] sfdisk: Davidlohr Bueso
2014-07-23  6:54 ` 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=1406072697-20912-13-git-send-email-davidlohr@hp.com \
    --to=davidlohr@hp.com \
    --cc=aswin@hp.com \
    --cc=kzak@redhat.com \
    --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).