Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 96756 invoked from network); 22 Sep 2006 22:46:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Sep 2006 22:46:05 -0000 Received: (qmail 37633 invoked by uid 500); 22 Sep 2006 22:46:05 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 37611 invoked by uid 500); 22 Sep 2006 22:46:05 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 37600 invoked by uid 99); 22 Sep 2006 22:46:05 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Sep 2006 15:46:05 -0700 Authentication-Results: idunn.apache.osuosl.org smtp.mail=ablack@roguewave.com; spf=permerror X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests= Received-SPF: error (idunn.apache.osuosl.org: domain roguewave.com from 208.30.140.160 cause and error) Received: from [208.30.140.160] ([208.30.140.160:45734] helo=moroha.quovadx.com) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id E7/80-24436-BA764154 for ; Fri, 22 Sep 2006 15:46:04 -0700 Received: from [10.70.3.48] ([10.70.3.48]) by moroha.quovadx.com (8.13.6/8.13.6) with ESMTP id k8MMj8w6018371 for ; Fri, 22 Sep 2006 22:45:08 GMT Message-ID: <451467A8.8090704@roguewave.com> Date: Fri, 22 Sep 2006 16:46:00 -0600 From: Andrew Black User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060910 SeaMonkey/1.0.5 MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: Re: cmdopt cleanup References: <45145CC9.6040408@roguewave.com> <4514655B.4060306@roguewave.com> In-Reply-To: <4514655B.4060306@roguewave.com> Content-Type: multipart/mixed; boundary="------------050501050803030002030704" X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------050501050803030002030704 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I think this fixes it. I did toss my check script at the file, but there was a fair amount of noise from the script. --Andrew Black Martin Sebor wrote: > Andrew Black wrote: >> Greetings all. >> >> Attached is a small patch that aims to clean up a few minor bugs in >> the cmdopt.cpp. Log below. > > This looks good. Just one thing -- can you please follow the > formatting style we discussed (i.e., space between a function > name and the opening parenthesis). > > Thanks > Martin > >> >> --Andrew Black >> >> Log: >> * cmdopt.cpp (parse_limit_opts): Restrict sub-option values to >> non-negative integers >> (eval_options): Ditto for -t, --exit, and --sleep, Fix off-by one >> error in logic for --ignore and --ulimit, leading to incorrect parsing >> >> >> ------------------------------------------------------------------------ >> >> Index: cmdopt.cpp >> =================================================================== >> --- cmdopt.cpp (revision 449032) >> +++ cmdopt.cpp (working copy) >> @@ -333,6 +333,10 @@ >> >> arg += limits [i].len + 1; >> >> + if (!isdigit(*arg)) { >> + return 1; >> + } >> + >> char *end; >> const long lim = strtol (arg, &end, 10); >> >> @@ -461,8 +465,10 @@ >> optname = opt_timeout; >> optarg = get_short_val (argv, &i); >> if (optarg) { >> + if (!isdigit(*optarg)) >> + bad_value (optname, optarg); >> timeout = strtol (optarg, &end, 10); >> - if (*end || timeout < 0 || errno) >> + if (*end || errno) >> bad_value (optname, optarg); >> } >> else >> @@ -512,6 +518,8 @@ >> optname = opt_exit; >> optarg = get_long_val (argv, &i, sizeof opt_exit - 1); >> if (optarg && *optarg) { >> + if (!isdigit(*optarg)) >> + bad_value (optname, optarg); >> const long code = strtol (optarg, &end, 10); >> if ('\0' == *end && !errno) >> exit (code); >> @@ -528,6 +536,8 @@ >> optname = opt_sleep; >> optarg = get_long_val (argv, &i, sizeof opt_sleep - 1); >> if (optarg && *optarg) { >> + if (!isdigit(*optarg)) >> + bad_value (optname, optarg); >> const long nsec = strtol (optarg, &end, 10); >> if ('\0' == *end && 0 <= nsec && !errno) { >> rw_sleep (nsec); >> @@ -549,10 +559,10 @@ >> } >> } >> } >> - else if ( sizeof opt_ignore <= arglen >> + else if ( sizeof opt_ignore - 1 <= arglen >> && !memcmp (opt_ignore, argv [i], sizeof >> opt_ignore - 1)) { >> optname = opt_ignore; >> - optarg = get_long_val (argv, &i, sizeof opt_ignore); >> + optarg = get_long_val (argv, &i, sizeof opt_ignore - >> 1); >> if (optarg && *optarg) { >> const long signo = get_signo (optarg); >> if (0 <= signo) { >> @@ -563,7 +573,7 @@ >> } >> } >> } >> - else if ( sizeof opt_ulimit <= arglen >> + else if ( sizeof opt_ulimit - 1 <= arglen >> && !memcmp (opt_ulimit, argv [i], sizeof >> opt_ulimit - 1)) { >> optname = opt_ulimit; >> optarg = get_long_val (argv, &i, sizeof opt_ulimit - >> 1); > --------------050501050803030002030704 Content-Type: text/x-patch; name="optfix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="optfix.diff" Index: cmdopt.cpp =================================================================== --- cmdopt.cpp (revision 449032) +++ cmdopt.cpp (working copy) @@ -333,6 +333,10 @@ arg += limits [i].len + 1; + if (!isdigit (*arg)) { + return 1; + } + char *end; const long lim = strtol (arg, &end, 10); @@ -461,8 +465,10 @@ optname = opt_timeout; optarg = get_short_val (argv, &i); if (optarg) { + if (!isdigit (*optarg)) + bad_value (optname, optarg); timeout = strtol (optarg, &end, 10); - if (*end || timeout < 0 || errno) + if (*end || errno) bad_value (optname, optarg); } else @@ -512,6 +518,8 @@ optname = opt_exit; optarg = get_long_val (argv, &i, sizeof opt_exit - 1); if (optarg && *optarg) { + if (!isdigit (*optarg)) + bad_value (optname, optarg); const long code = strtol (optarg, &end, 10); if ('\0' == *end && !errno) exit (code); @@ -528,6 +536,8 @@ optname = opt_sleep; optarg = get_long_val (argv, &i, sizeof opt_sleep - 1); if (optarg && *optarg) { + if (!isdigit (*optarg)) + bad_value (optname, optarg); const long nsec = strtol (optarg, &end, 10); if ('\0' == *end && 0 <= nsec && !errno) { rw_sleep (nsec); @@ -549,10 +559,10 @@ } } } - else if ( sizeof opt_ignore <= arglen + else if ( sizeof opt_ignore - 1 <= arglen && !memcmp (opt_ignore, argv [i], sizeof opt_ignore - 1)) { optname = opt_ignore; - optarg = get_long_val (argv, &i, sizeof opt_ignore); + optarg = get_long_val (argv, &i, sizeof opt_ignore - 1); if (optarg && *optarg) { const long signo = get_signo (optarg); if (0 <= signo) { @@ -563,7 +573,7 @@ } } } - else if ( sizeof opt_ulimit <= arglen + else if ( sizeof opt_ulimit - 1 <= arglen && !memcmp (opt_ulimit, argv [i], sizeof opt_ulimit - 1)) { optname = opt_ulimit; optarg = get_long_val (argv, &i, sizeof opt_ulimit - 1); --------------050501050803030002030704--