From 4fedf388f68b49dd1a8334f75272c3bfddd6032c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Thu, 26 Jul 2012 16:05:51 +0200 Subject: [PATCH] virsh: check if specified debug level is in range --- .mailmap | 1 + tools/virsh.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.mailmap b/.mailmap index 367315963c..9b0209e3fd 100644 --- a/.mailmap +++ b/.mailmap @@ -36,3 +36,4 @@ Alex Jia Royce Lv Daniel J Walsh +Ján Tomko diff --git a/tools/virsh.c b/tools/virsh.c index 5658796424..4f8ea941e9 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -3073,7 +3073,7 @@ vshAllowedEscapeChar(char c) static bool vshParseArgv(vshControl *ctl, int argc, char **argv) { - int arg, len; + int arg, len, debug; struct option opt[] = { {"debug", required_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, @@ -3093,10 +3093,15 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) while ((arg = getopt_long(argc, argv, "+d:hqtc:vVrl:e:", opt, NULL)) != -1) { switch (arg) { case 'd': - if (virStrToLong_i(optarg, NULL, 10, &ctl->debug) < 0) { + if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) { vshError(ctl, "%s", _("option -d takes a numeric argument")); exit(EXIT_FAILURE); } + if (debug < VSH_ERR_DEBUG || debug > VSH_ERR_ERROR) + vshError(ctl, _("ignoring debug level %d out of range [%d-%d]"), + debug, VSH_ERR_DEBUG, VSH_ERR_ERROR); + else + ctl->debug = debug; break; case 'h': vshUsage();