From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 13 12:18:35 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 29F4416A4CE for ; Fri, 13 Aug 2004 12:18:35 +0000 (GMT) Received: from britannica.bec.de (port-212-202-135-63.static.qsc.de [212.202.135.63]) by mx1.FreeBSD.org (Postfix) with ESMTP id EAE9343D2F for ; Fri, 13 Aug 2004 12:18:33 +0000 (GMT) (envelope-from joerg@britannica.bec.de) Received: from britannica.bec.de (localhost [127.0.0.1]) by britannica.bec.de (8.12.10/8.12.10) with ESMTP id i7DCHMsE000984 for ; Fri, 13 Aug 2004 14:17:33 +0200 (CEST) (envelope-from joerg@britannica.bec.de) Received: (from joerg@localhost) by britannica.bec.de (8.12.10/8.12.10/Submit) id i7DCHBw6000983 for freebsd-hackers@freebsd.org; Fri, 13 Aug 2004 14:17:11 +0200 (CEST) Date: Fri, 13 Aug 2004 14:17:11 +0200 From: Joerg Sonnenberger To: freebsd-hackers@freebsd.org Message-ID: <20040813121711.GC839@britannica.bec.de> Mail-Followup-To: freebsd-hackers@freebsd.org References: <20040811193254.6f0be2c2.thib@mi.is> <20040811200323.GA37059@xor.obsecurity.org> <20040811203832.728c915b.thib@mi.is> <20040812231519.GB7173@gothmog.gr> <20040813111849.047fae64.thib@mi.is> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040813111849.047fae64.thib@mi.is> User-Agent: Mutt/1.4.2.1i Subject: Re: Where is strnlen() ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2004 12:18:35 -0000 On Fri, Aug 13, 2004 at 11:18:49AM +0000, Thordur Ivar B. wrote: > I agree but what I was thinking at the time if I'm reciving user input to a > program wich uses strlen I might be vonerable to buffer overflow attacks (But > that has been cleard up) and ofcourse in most cases you know the length of a > string you are using (exept when you are dealing with user input, wich was the > case in my porting effort.) And since I'm a pedant I think that interducing > new non-standard functions is not an option so I think I will have to > "turn-my-brain-on" as I mentioned in a previous post. size_t strnlen(const void *str, size_t len) { const void *end = memchr(str, '\0', len); if (end == NULL) return -1; /* len ? */ return (size_t)(end - str); } Or similiar in your code should do the trick. Joerg > > Anyways thanks for the replays. > > -- > As far as the laws of mathematics refer to reality, they are not > certain, and as far as they are certain, they do not refer to reality. > -- Albert Einstein > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"