From owner-freebsd-bugs@FreeBSD.ORG Mon Jun 22 20:20:02 2009 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 1DFCE10656CF for ; Mon, 22 Jun 2009 20:20: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 D1E0E8FC1F for ; Mon, 22 Jun 2009 20:20:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n5MKK11M045611 for ; Mon, 22 Jun 2009 20:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n5MKK1iK045610; Mon, 22 Jun 2009 20:20:01 GMT (envelope-from gnats) Resent-Date: Mon, 22 Jun 2009 20:20:01 GMT Resent-Message-Id: <200906222020.n5MKK1iK045610@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, Yuri Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3BE121065672 for ; Mon, 22 Jun 2009 20:16:51 +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 29E848FC14 for ; Mon, 22 Jun 2009 20:16:51 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n5MKGog9028740 for ; Mon, 22 Jun 2009 20:16:50 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n5MKGoDj028739; Mon, 22 Jun 2009 20:16:50 GMT (envelope-from nobody) Message-Id: <200906222016.n5MKGoDj028739@www.freebsd.org> Date: Mon, 22 Jun 2009 20:16:50 GMT From: Yuri To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/135932: 'strtol' doesn't reset errno to 0 when converting MAX_INT=2147483647 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: Mon, 22 Jun 2009 20:20:02 -0000 >Number: 135932 >Category: misc >Synopsis: 'strtol' doesn't reset errno to 0 when converting MAX_INT=2147483647 >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jun 22 20:20:01 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Yuri >Release: 72-STABLE >Organization: n/a >Environment: >Description: When strtol is supplied string 2147483647 it's impossible to distinguish between overflow and non-overflow situation since return value is the same one that flags overflow (MAX_INT) and strtol doesn't clear errno in this case. strtol should set errno=0 in this case to avoid ambiguity. errno can accidentally be set to 34 (ERANGE) before the call and this will affect the conversion decision in this case. And requiring all programs to reset errno before the call isn't right too since the proposed here simple fix fixes this ambiguity for every program. -- testcase -- #include #include #include #include main() { const char *nptr = "2147483647"; char *endptr; errno=34; // ERANGE int res = ::strtol(nptr, &endptr, 10); printf("res=%i errno=%i\n", res, errno); } --- output --- res=2147483647 errno=34 >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: