NetBSD Problem Report #27140
Received: (qmail 13872 invoked by uid 605); 4 Oct 2004 14:04:47 -0000
Message-Id: <20041004140411.05C82294A2@dmath5.geometrie.tuwien.ac.at>
Date: Mon, 4 Oct 2004 16:04:11 +0200 (CEST)
From: wiz@NetBSD.org
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: wiz@NetBSD.org
To: gnats-bugs@gnats.NetBSD.org
Subject: "sleep time" doesn't error out
X-Send-Pr-Version: 3.95
>Number: 27140
>Category: bin
>Synopsis: "sleep time" doesn't error out
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Oct 04 14:05:00 +0000 2004
>Closed-Date: Mon Oct 17 10:12:20 +0000 2005
>Last-Modified: Fri Mar 30 09:30:07 +0000 2012
>Originator: Thomas Klausner
>Release: NetBSD 2.0_BETA
>Organization:
>Environment:
Architecture: i386
Machine: i386
>Description:
"sleep time" produces no error, even though sleep(1) gets a non-numeric
argument.
>How-To-Repeat:
# sleep time
#
>Fix:
Fix the argument handling in sleep(1); not provided.
>Release-Note:
>Audit-Trail:
From: SODA Noriyuki <soda@sra.co.jp>
To: wiz@NetBSD.org
Cc: gnats-bugs@gnats.NetBSD.org
Subject: Re: bin/27140: "sleep time" doesn't error out
Date: Mon, 4 Oct 2004 23:44:59 +0900 (JST)
>>>>> On Mon, 4 Oct 2004 16:04:11 +0200 (CEST), wiz@NetBSD.org said:
> "sleep time" produces no error, even though sleep(1) gets a non-numeric
Isn't this trivial to fix?
e.g.
Index: sleep.c
===================================================================
RCS file: /cvsroot/src/bin/sleep/sleep.c,v
retrieving revision 1.19
diff -u -r1.19 sleep.c
--- sleep.c 7 Aug 2003 09:05:41 -0000 1.19
+++ sleep.c 4 Oct 2004 14:38:09 -0000
@@ -60,10 +60,10 @@
int
main(int argc, char *argv[])
{
- char *arg, *temp;
- double fval, ival, val;
+ char *ep;
+ double ival, val;
struct timespec ntime;
- int ch, fracflag;
+ int ch;
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
@@ -83,37 +83,30 @@
usage();
/*
- * Okay, why not just use atof for everything? Why bother
+ * Okay, why not just use strtod() for everything? Why bother
* checking if there is a fraction in use? Because the old
* sleep handled the full range of integers, that's why, and a
* double can't handle a large long. This is fairly useless
* given how large a number a double can hold on most
* machines, but now we won't ever have trouble. If you want
* 1000000000.9 seconds of sleep, well, that's your
- * problem. Why use an isdigit() check instead of checking for
- * a period? Because doing it this way means locales will be
- * handled transparently by the atof code.
+ * problem.
*/
- fracflag = 0;
- arg = *argv;
- for (temp = arg; *temp != '\0'; temp++)
- if (!isdigit((unsigned char)*temp))
- fracflag++;
-
- if (fracflag) {
- val = atof(arg);
- if (val <= 0)
+ ntime.tv_sec = strtol(argv[0], &ep, 10);
+ if (argv[0][0] != '\0' && ep[0] == '\0') {
+ if (ntime.tv_sec < 0)
+ exit(0);
+ ntime.tv_nsec = 0;
+ } else {
+ val = strtod(argv[0], &ep);
+ if (argv[0][0] == '\0' || ep[0] != '\0' ||
+ isinf(val) || isnan(val))
+ errx(2, "invalid time interval %s", argv[0]);
+ if (val < 0)
exit(0);
ival = floor(val);
- fval = (1000000000 * (val-ival));
ntime.tv_sec = ival;
- ntime.tv_nsec = fval;
- }
- else{
- ntime.tv_sec = atol(arg);
- if (ntime.tv_sec <= 0)
- exit(0);
- ntime.tv_nsec = 0;
+ ntime.tv_nsec = (1000000000 * (val - ival));
}
if (nanosleep(&ntime, NULL) == -1)
P.S.
Maybe it's better to convert isinf() case to LONG_MAX, but it seems
currently our nanosleep() doesn't support LONG_MAX as tv_sec.
--
soda
From: "Dheeraj Reddy" <dheeraj@ece.gatech.edu>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/27140
Date: Mon, 4 Oct 2004 18:48:22 -0400
Or maybe just the following patch does it ?
Index: sleep.c
===================================================================
RCS file: /cvsroot/src/bin/sleep/sleep.c,v
retrieving revision 1.19
diff -r1.19 sleep.c
105c105,106
< if (val <= 0)
---
> if (val <= 0) {
> usage();
106a108
> }
--
It is better to be silent and be thought a fool than to speak and remove
all doubt
From: Elad Efrat <elad@netbsd.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: PR/27140 CVS commit: src/bin/sleep
Date: Mon, 17 Oct 2005 10:11:46 +0000 (UTC)
Module Name: src
Committed By: elad
Date: Mon Oct 17 10:11:46 UTC 2005
Modified Files:
src/bin/sleep: sleep.c
Log Message:
PR/27140: "sleep time" doesn't error out.
Apply fix from Dheeraj Reddy.
To generate a diff of this commit:
cvs rdiff -r1.19 -r1.20 src/bin/sleep/sleep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: elad@netbsd.org
State-Changed-When: Mon, 17 Oct 2005 10:12:20 +0000
State-Changed-Why:
Fixed, thanks.
From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/27140 CVS commit: src
Date: Fri, 30 Mar 2012 09:27:11 +0000
Module Name: src
Committed By: jruoho
Date: Fri Mar 30 09:27:10 UTC 2012
Modified Files:
src/distrib/sets/lists/tests: mi
src/etc/mtree: NetBSD.dist.tests
Added Files:
src/tests/bin/sleep: Makefile t_sleep.sh
Log Message:
Add regression tests for PR bin/3914 and PR bin/27140.
To generate a diff of this commit:
cvs rdiff -u -r1.461 -r1.462 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.70 -r1.71 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r0 -r1.1 src/tests/bin/sleep/Makefile \
src/tests/bin/sleep/t_sleep.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.