From owner-freebsd-hackers Tue Oct 22 11:58:16 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id LAA23196 for hackers-outgoing; Tue, 22 Oct 1996 11:58:16 -0700 (PDT) Received: from alpo.whistle.com (alpo.whistle.com [207.76.204.38]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id LAA23190 for ; Tue, 22 Oct 1996 11:58:12 -0700 (PDT) Received: from current1.whistle.com (current1.whistle.com [207.76.205.22]) by alpo.whistle.com (8.7.6/8.7.3) with SMTP id LAA09558; Tue, 22 Oct 1996 11:55:28 -0700 (PDT) Message-ID: <326D1817.1CFBAE39@whistle.com> Date: Tue, 22 Oct 1996 11:53:11 -0700 From: Julian Elischer Organization: Whistle Communications X-Mailer: Mozilla 3.0b6 (X11; I; FreeBSD 2.2-CURRENT i386) MIME-Version: 1.0 To: "Daniel O'Callaghan" CC: freebsd-hackers@freebsd.org Subject: Re: libc string routines don't check for NULL pointers References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Daniel O'Callaghan wrote: This comes up about every 6 months for the last 10 years on the newsgroups.. the functions are SUPPOSED to segv you are NOT SUPPOSED TO call them with null pointers you are supposed to CHECK THEM BEFORE. this is so that yuou can check a string is non null, use it in 57 consecutive operations and have only wasted teh effort of checking it once. fix the program. > > The string comparison (and other) routines in libc don't check for null > pointers being passed. This results in SEGVs if one or both of the > string pointers being passed is NULL. I can see a religious debate here, > but I'm going to raise the issue: Should str*cmp() handle NULL arguments. > > I have made the very simple change necessary to strcmp() for it to return > > 0 - strings are the same, or pointers are both NULL > < 0 - s1 < s2, or s1 == NULL > > 0 - s1 > s2 or s2 == NULL > > I'd like to see my changes made to libc, but what do others think - > should it be just "the programmer's stupid fault" if (s)he passes a NULL > pointer to these routines, or should the routines handle NULL? > > Danny