diff options
author | Jim Meyering <meyering@redhat.com> | 2009-02-07 17:17:54 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2009-02-07 17:22:00 +0100 |
commit | 29e1a79630c51321f851d762c45b2bd99afeaec7 (patch) | |
tree | df96b5c7bd1f90470b232dbf28f1320a88830e4e /debug | |
parent | 632dfafdea025bae9a24651022c9147ef3fe8019 (diff) | |
download | parted-29e1a79630c51321f851d762c45b2bd99afeaec7.tar.gz |
clearfat: diagnose an invalid device number
* debug/clearfat/clearfat.c: Include <limits.h> and "xstrtol.h".
(main): Diagnose an invalid minor device number argument.
* bootstrap.conf (gnulib_modules): Add xstrtol.
Diffstat (limited to 'debug')
-rw-r--r-- | debug/clearfat/clearfat.c | 16 |
1 files changed, 13 insertions, 3 deletions
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 <string.h> #include <stdio.h> #include <stdlib.h> +#include <limits.h> #include <getopt.h> #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; |