From owner-freebsd-hackers Wed Feb 12 01:37:48 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id BAA18562 for hackers-outgoing; Wed, 12 Feb 1997 01:37:48 -0800 (PST) Received: from panda.hilink.com.au (panda.hilink.com.au [203.2.144.5]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id BAA18553 for ; Wed, 12 Feb 1997 01:37:42 -0800 (PST) Received: (from danny@localhost) by panda.hilink.com.au (8.7.6/8.7.3) id UAA07696; Wed, 12 Feb 1997 20:42:26 +1100 (EST) Date: Wed, 12 Feb 1997 20:42:25 +1100 (EST) From: "Daniel O'Callaghan" To: Joerg Wunsch cc: hackers@freebsd.org Subject: Re: strlen() question In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk On Wed, 12 Feb 1997, J Wunsch wrote: > As Daniel O'Callaghan wrote: > > > Below is the code for strlen() from libc. It is extremely simple, and > > fast. Is it really safe to assume that strlen() will never exceed process > > memory bounds before striking a '\0'? Or should there be a strnlen() > > function in libc for checking the length of suspicious strings? > > Why? The worst that would happen by touching off the end of your > address space is a SIGSEGV. The problem with str*cpy() touching > beyond the bounds of their arrays is that they can _modify_ the stack > then, but that can't happen with strlen() since it doesn't modify > anything. I was thinking of bounds checking w/o a copy. Danny