From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 1 22:20:13 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9349416A4CE for ; Tue, 1 Mar 2005 22:20:13 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4FD4B43D3F for ; Tue, 1 Mar 2005 22:20:13 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id j21MKDWr014919 for ; Tue, 1 Mar 2005 22:20:13 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id j21MKDXm014918; Tue, 1 Mar 2005 22:20:13 GMT (envelope-from gnats) Resent-Date: Tue, 1 Mar 2005 22:20:13 GMT Resent-Message-Id: <200503012220.j21MKDXm014918@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, Dan Allen Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0030016A4CE for ; Tue, 1 Mar 2005 22:17:46 +0000 (GMT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id DCC2A43D3F for ; Tue, 1 Mar 2005 22:17:46 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j21MHk6w083525 for ; Tue, 1 Mar 2005 22:17:46 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id j21MHkuL083524; Tue, 1 Mar 2005 22:17:46 GMT (envelope-from nobody) Message-Id: <200503012217.j21MHkuL083524@www.freebsd.org> Date: Tue, 1 Mar 2005 22:17:46 GMT From: Dan Allen To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: misc/78256: strstr could be more robust X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2005 22:20:13 -0000 >Number: 78256 >Category: misc >Synopsis: strstr could be more robust >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Mar 01 22:20:12 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Dan Allen >Release: 5.4 PRERELEASE >Organization: >Environment: FreeBSD 5.4-PRERELEASE >Description: strstr does not check to see if its first argument is null or not. The ISO standard is silent about error checking the first argument, but it seems to me that a single line of code could make strstr more robust. >How-To-Repeat: char *p = getenv("TERM"); int i = strstr(p,"cons25") ? 1 : 0; Runs fine from a console or from xterm under X-Windows, but if in a tool running under cron where TERM is not defined it causes a segmentation fault. I know that I should test for a null string from getenv, but it seems that a bullet-proof strstr should have the fix shown below... >Fix: Add as the first line of code in strstr: if (!s) return NULL; to fix the problem. >Release-Note: >Audit-Trail: >Unformatted: