summaryrefslogtreecommitdiffstats
path: root/disk-utils
diff options
context:
space:
mode:
authorSami Kerola2012-03-17 20:27:43 +0100
committerKarel Zak2012-03-30 16:48:12 +0200
commitd5fc1b1581c2054caa8671e1119ec803bdbc3326 (patch)
treec5591d08e469e109678a2319abdd8ce12c62258a /disk-utils
parentraw: use pathnames.h for file locations (diff)
downloadkernel-qcow2-util-linux-d5fc1b1581c2054caa8671e1119ec803bdbc3326.tar.gz
kernel-qcow2-util-linux-d5fc1b1581c2054caa8671e1119ec803bdbc3326.tar.xz
kernel-qcow2-util-linux-d5fc1b1581c2054caa8671e1119ec803bdbc3326.zip
raw: check numeric user inputs
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'disk-utils')
-rw-r--r--disk-utils/raw.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/disk-utils/raw.c b/disk-utils/raw.c
index 2766bcef5..8844bc264 100644
--- a/disk-utils/raw.c
+++ b/disk-utils/raw.c
@@ -65,6 +65,29 @@ static void __attribute__ ((__noreturn__)) usage(int err)
}
+long strtol_octal_or_err(const char *str, const char *errmesg)
+{
+ long num;
+ char *end = NULL;
+
+ if (str == NULL || *str == '\0')
+ goto err;
+ errno = 0;
+ num = strtol(str, &end, 0);
+
+ if (errno || str == end || (end && *end))
+ goto err;
+
+ return num;
+ err:
+ if (errno)
+ err(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+ else
+ errx(EXIT_FAILURE, "%s: '%s'", errmesg, str);
+ return 0;
+}
+
+
int main(int argc, char *argv[])
{
int c;
@@ -168,8 +191,12 @@ int main(int argc, char *argv[])
break;
case 2:
- block_major = strtol(argv[optind], 0, 0);
- block_minor = strtol(argv[optind+1], 0, 0);
+ block_major =
+ strtol_octal_or_err(argv[optind],
+ _("failed to parse argument"));
+ block_minor =
+ strtol_octal_or_err(argv[optind + 1],
+ _("failed to parse argument"));
break;
default: