Subject: lib/4005: usleep() fails on large arguments
To: None <gnats-bugs@gnats.netbsd.org>
From: maximum entropy <entropy@tardis.bernstein.com>
List: netbsd-bugs
Date: 08/18/1997 08:31:31
>Number: 4005
>Category: lib
>Synopsis: usleep() fails on large arguments
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Aug 18 05:35:00 1997
>Last-Modified:
>Originator: maximum entropy
>Organization:
>Release: <NetBSD-current source date> 19970811
>Environment:
Anything running with the most recent version of usleep.c in libc
System: NetBSD tardis.bernstein.com 1.2G NetBSD 1.2G (C466DE) #0: Mon Aug 11 13:29:35 EDT 1997 entropy@tardis.bernstein.com:/usr/src/sys/arch/i386/compile/C466DE i386
>Description:
If usleep() is passed a value greater than UINT_MAX/1000, the call to
nanosleep() fails (EINVAL) and usleep() returns immediately.
The problem was reported on the NetBSD-current mailing list by
Rick Byers <rickb@iaw.on.ca>.
>How-To-Repeat:
#include <unistd.h>
extern int errno;
int
main()
{
errno = 0;
usleep((unsigned int) (15000000);
perror("usleep");
}
>Fix:
--- /usr/src/lib/libc/gen/usleep.c.orig Tue Jul 22 07:12:44 1997
+++ /usr/src/lib/libc/gen/usleep.c Mon Aug 18 05:37:53 1997
@@ -55,8 +55,8 @@
{
struct timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = useconds * 1000;
+ ts.tv_sec = useconds / 1000000;
+ ts.tv_nsec = (useconds % 1000000) * 1000;
nanosleep(&ts, NULL);
}
>Audit-Trail:
>Unformatted: