This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
An enhancement of -p option checking so as to accept only one digital number
- From: Sunzen Wang <sunzen at gmail dot com>
- To: systemtap at sources dot redhat dot com
- Date: Fri, 15 May 2009 19:37:33 +0800
- Subject: An enhancement of -p option checking so as to accept only one digital number
Let -p option only accept one digital number (between 1-5)
Due to the behavior of atoi(convert the initial portion of the
specified string), currently odd optargs with pattern of
"[digital-number][non-digital]+" (e.g, 1df) are 'sadly' accepted.
With minimal patch code, the below fix enhances the option checking.
Is this too protective? IMHO, it seems not. How about it?
--
diff --git a/main.cxx b/main.cxx
index 1ac5dd5..38d2a95 100644
--- a/main.cxx
+++ b/main.cxx
@@ -519,7 +519,7 @@ main (int argc, char * const argv [])
usage (s, 1);
}
s.last_pass = atoi (optarg);
- if (s.last_pass < 1 || s.last_pass > 5)
+ if (strlen(optarg) > 1 || s.last_pass < 1 || s.last_pass > 5)
{
cerr << "Invalid pass number (should be 1-5)." << endl;
usage (s, 1);
--
--
sunzen
<<freedom & enjoyment>>