From owner-freebsd-bugs@FreeBSD.ORG Thu Aug 26 06:00:17 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A73941065693 for ; Thu, 26 Aug 2010 06:00:17 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 759338FC18 for ; Thu, 26 Aug 2010 06:00:17 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o7Q60Hc6093371 for ; Thu, 26 Aug 2010 06:00:17 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o7Q60Hcs093370; Thu, 26 Aug 2010 06:00:17 GMT (envelope-from gnats) Resent-Date: Thu, 26 Aug 2010 06:00:17 GMT Resent-Message-Id: <201008260600.o7Q60Hcs093370@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 99AE31065670 for ; Thu, 26 Aug 2010 05:50:05 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 669538FC08 for ; Thu, 26 Aug 2010 05:50:05 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o7Q5o5po065100 for ; Thu, 26 Aug 2010 05:50:05 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o7Q5o5hf065099; Thu, 26 Aug 2010 05:50:05 GMT (envelope-from nobody) Message-Id: <201008260550.o7Q5o5hf065099@www.freebsd.org> Date: Thu, 26 Aug 2010 05:50:05 GMT From: Garrett Cooper To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/149980: [PATCH] negative value integer to nanosleep(2) should fail with EINVAL X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Aug 2010 06:00:17 -0000 >Number: 149980 >Category: kern >Synopsis: [PATCH] negative value integer to nanosleep(2) should fail with EINVAL >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Thu Aug 26 06:00:16 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Garrett Cooper >Release: 9-CURRENT >Organization: Cisco Systems, Inc. >Environment: FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #9 r211309M: Thu Aug 19 22:50:36 PDT 2010 root@bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA amd64 >Description: After some discussion with the POSIX folks, the spec doesn't discuss the tv_sec quantity, partly because the time_t value that gets plugged in for tv_sec can be positive or negative, depending on the implementation in the operating system. In FreeBSD time_t is signed, and in Linux it's unsigned. Signedness values aside, it doesn't make sense to sleep negative time, because PCs shouldn't be traveling to the past :). The patch clearly notes the positive real number requirement and addresses the < 0 quantity issue at the kernel level. # BEFORE $ ./test_nanosleep_negative_time passed unexpectedly # AFTER $ ./test_nanosleep_negative_time failed as expected $ echo $? 0 >How-To-Repeat: 1. Compile the following program: #include #include #include #include int main(void) { struct timespec rqtp; rqtp.tv_sec = -1; rqtp.tv_nsec = 0; if (nanosleep(&rqtp, NULL) == -1) { if (errno == EINVAL) { printf("failed as expected\n"); return (0); } else warn("failed unexpectedly"); } else printf("passed unexpectedly\n"); return (1); } 2. Execute the compiled binary. >Fix: Patch attached with submission follows: Index: lib/libc/sys/nanosleep.2 =================================================================== --- lib/libc/sys/nanosleep.2 (revision 211794) +++ lib/libc/sys/nanosleep.2 (working copy) @@ -93,6 +93,11 @@ The .Fa rqtp argument +specified a second value less than zero. +.It Bq Er EINVAL +The +.Fa rqtp +argument specified a nanosecond value less than zero or greater than or equal to 1000 million. .It Bq Er ENOSYS Index: sys/kern/kern_time.c =================================================================== --- sys/kern/kern_time.c (revision 211794) +++ sys/kern/kern_time.c (working copy) @@ -358,7 +358,9 @@ if (rqt->tv_nsec < 0 || rqt->tv_nsec >= 1000000000) return (EINVAL); - if (rqt->tv_sec < 0 || (rqt->tv_sec == 0 && rqt->tv_nsec == 0)) + if (rqt->tv_sec < 0) + return (EINVAL); + if (rqt->tv_sec == 0 && rqt->tv_nsec == 0) return (0); getnanouptime(&ts); timespecadd(&ts, rqt); >Release-Note: >Audit-Trail: >Unformatted: