lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170904150015.GB30364@orbyte.nwl.cc>
Date:   Mon, 4 Sep 2017 17:00:15 +0200
From:   Phil Sutter <phil@....cc>
To:     David Laight <David.Laight@...LAB.COM>
Cc:     Stephen Hemminger <stephen@...workplumber.org>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: Re: [iproute PATCH 1/6] utils: Implement strlcpy() and strlcat()

On Mon, Sep 04, 2017 at 02:49:20PM +0000, David Laight wrote:
> From: Phil Sutter
> > Sent: 01 September 2017 17:53
> > By making use of strncpy(), both implementations are really simple so
> > there is no need to add libbsd as additional dependency.
> > 
> ...
> > +
> > +size_t strlcpy(char *dst, const char *src, size_t size)
> > +{
> > +	if (size) {
> > +		strncpy(dst, src, size - 1);
> > +		dst[size - 1] = '\0';
> > +	}
> > +	return strlen(src);
> > +}
> 
> Except that isn't really strlcpy().
> Better would be:
> 	len = strlen(src) + 1;
> 	if (len <= size)
> 		memcpy(dst, src, len);
> 	else if (size) {
> 		dst[size - 1] = 0;
> 		memcpy(dst, src, size - 1);
> 	}
> 	return len - 1;

Please elaborate: Why isn't my version "really" strlcpy()? Why is your
proposed version better?

Thanks, Phil

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ