Subject: Re: copyinstr() with a zero-length buffer
To: Chuck Silvers <chuq@chuq.com>
From: Chris G. Demetriou <cgd@netbsd.org>
List: tech-kern
Date: 11/02/1999 00:23:56
Chuck Silvers <chuq@chuq.com> writes:
> here's a philosophical question for ya:  is it legal to call copyinstr()
> with maxlen == 0?  the sparc will panic if this happens, but the sample
> program in PR 7838 will cause sys_execve() to do just that.
> so which is wrong?

I would say the sparc code, for a couple of reasons:

* i've never seen documentation that says that 0 is an illegal maxlen.
All of the documentation that i've seen makes you think that it's an
OK value.  (no justification for the behaviour)

* strncpy() and memcpy() et al. all are happy with a 0 length.
(consistency with other functions that copy stuff into buffers)

* i believe that many/most of the rest of the ports handle the 0
maxlen case (consistency with other ports' implementations of the same
functions)

* the 4.4-Lite hp300 and i386 ports seem to accept 0 maxlen (appeal
to authority; the hp300 port was the most tested 4.4-Lite port.  On
the other hand, Lite sparc code seems to reject it, and it looks
like the 4.4 pmax code would just choke... 8-)



i'd say a maxlen of 0 is OK...


cgd
-- 
Chris Demetriou - cgd@netbsd.org - http://www.netbsd.org/People/Pages/cgd.html
Disclaimer: Not speaking for NetBSD, just expressing my own opinion.