From owner-freebsd-bugs@FreeBSD.ORG Sun Jul 6 17:40:02 2008 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 B82EA1065679 for ; Sun, 6 Jul 2008 17:40:02 +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 929AE8FC18 for ; Sun, 6 Jul 2008 17:40:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m66He2ON011426 for ; Sun, 6 Jul 2008 17:40:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m66He2BC011425; Sun, 6 Jul 2008 17:40:02 GMT (envelope-from gnats) Resent-Date: Sun, 6 Jul 2008 17:40:02 GMT Resent-Message-Id: <200807061740.m66He2BC011425@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, Jilles Tjoelker Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9D3641065688 for ; Sun, 6 Jul 2008 17:30:28 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (meestal-mk5.stack.nl [IPv6:2001:610:1108:5010::149]) by mx1.freebsd.org (Postfix) with ESMTP id 5F9E18FC1E for ; Sun, 6 Jul 2008 17:30:28 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id 6B2E43F7FC for ; Sun, 6 Jul 2008 19:30:27 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id 62ABE33C7F; Sun, 6 Jul 2008 19:30:27 +0200 (CEST) Message-Id: <20080706173027.62ABE33C7F@turtle.stack.nl> Date: Sun, 6 Jul 2008 19:30:27 +0200 (CEST) From: Jilles Tjoelker To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/125338: [PATCH] expand_number(3) silently truncates numeric part on i386 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jul 2008 17:40:02 -0000 >Number: 125338 >Category: kern >Synopsis: [PATCH] expand_number(3) silently truncates numeric part on i386 >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Jul 06 17:40:02 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Jilles Tjoelker >Release: FreeBSD 7.0-STABLE i386 >Organization: MCGV Stack >Environment: System: FreeBSD turtle.stack.nl 7.0-STABLE FreeBSD 7.0-STABLE #0: Tue May 20 22:43:27 CEST 2008 root@snail.stack.nl:/sabretooth.mnt/sources/6.x/i386/obj/sabretooth.mnt/sources/7.x/src/sys/STACK-SMP i386 problem present in -CURRENT sources as well >Description: On i386, if the numeric part of the string passed to expand_number(3) does not fit in 32 bits, e.g. "5368709120k" it is truncated. >How-To-Repeat: Detailed how-to-repeat from Alexandre Sunny Kovalenko: sunny:RabbitsDen>./expand_number 5368709120k Result is 1099511627776 sunny:RabbitsDen>./expand_number 5120G Result is 5497558138880 sunny:RabbitsDen> The expected result is 5497558138880 for both. test program (needs to be linked with -lutil) #include #include #include #include #include #include #include int main(int argc, char *argv[]) { if(argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } errno = 0; intmax_t result; if(expand_number(argv[1], &result) || errno) { perror("Expand number"); exit(1); } printf("Result is %jd\n", result); exit(0); } >Fix: The problem occurs because src/lib/libutil/expand_number.c does not include the necessary header for calling strtoimax(3). The file is compiled without compiler warnings, so the bug shows up as wrong behaviour. Adding #include fixes it. The file is slightly changed in CURRENT but the same patch should apply. --- expand_number.patch begins here --- --- src/lib/libutil/expand_number.c.orig 2007-09-05 16:27:13.000000000 +0200 +++ src/lib/libutil/expand_number.c 2008-07-06 13:11:02.766238000 +0200 @@ -33,6 +33,7 @@ #include #include #include +#include /* * Convert an expression of the following forms to a int64_t. --- expand_number.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: