Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Aug 2000 13:58:16 -0700 (PDT)
From:      Kris Kennaway <kris@hub.freebsd.org>
To:        Warner Losh <imp@village.org>
Cc:        audit@FreeBSD.ORG
Subject:   Re: ether_line() patch 
Message-ID:  <Pine.BSF.4.21.0008041355250.64303-100000@hub.freebsd.org>
In-Reply-To: <200008041927.NAA12389@harmony.village.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 4 Aug 2000, Warner Losh wrote:

> : -			strncpy(buf, result, resultlen);
> : +			strncpy(buf, result, resultlen - 1);
> :  			buf[resultlen] = '\0';
> :  			free(result);
> :  		}
> : 
> 
> This change is wrong.  The strcpy puts upto resultlen characters into
> buf, and then null terminates it at the resultlen + 1st character
> (counting from 1).  The strncpy should therefore not have the -1.  Or
> the line setting the buf[] = 0 should have it as well.

strncpy does not null-terminate if strlen(result) == resultlen. In that
case the buf[resultlen] character will be stomped by the NULL - it's a
trivial change, but I think it's correct.

Kris

--
In God we Trust -- all others must submit an X.509 certificate.
    -- Charles Forsythe <forsythe@alum.mit.edu>



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0008041355250.64303-100000>