From 29e1a79630c51321f851d762c45b2bd99afeaec7 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 7 Feb 2009 17:17:54 +0100 Subject: clearfat: diagnose an invalid device number * debug/clearfat/clearfat.c: Include and "xstrtol.h". (main): Diagnose an invalid minor device number argument. * bootstrap.conf (gnulib_modules): Add xstrtol. --- debug/clearfat/clearfat.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'debug') diff --git a/debug/clearfat/clearfat.c b/debug/clearfat/clearfat.c index 7a4c61f..69bc357 100644 --- a/debug/clearfat/clearfat.c +++ b/debug/clearfat/clearfat.c @@ -1,6 +1,6 @@ /* clear_fat - a tool to clear unused space (for testing purposes) - Copyright (C) 2000, 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2000, 2007-2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,12 +21,14 @@ #include #include #include +#include #include #include "closeout.h" #include "configmake.h" #include "error.h" #include "long-options.h" #include "progname.h" +#include "xstrtol.h" #include "../../libparted/fs/fat/fat.h" @@ -288,6 +290,14 @@ main (int argc, char* argv[]) usage (EXIT_FAILURE); } + unsigned long minor_dev_number; + if (xstrtoul (argv[2], NULL, 10, &minor_dev_number, NULL) + || INT_MAX < minor_dev_number) + { + error (0, 0, _("invalid minor device number: %s"), argv[2]); + usage (EXIT_FAILURE); + } + dev = ped_device_get (argv [1]); if (!dev) goto error; @@ -297,8 +307,8 @@ main (int argc, char* argv[]) disk = ped_disk_new (dev); if (!disk) goto error_close_dev; - - part = ped_disk_get_partition (disk, atoi (argv[2])); + + part = ped_disk_get_partition (disk, minor_dev_number); if (!part) { printf ("Couldn't find partition `%s'\n", argv[2]); goto error_destroy_disk; -- cgit v1.2.1