Re: strscpy

Kamil Rytarowski <[email protected]> Tue, 19 May 2020 18:54:14 +0200
Newsgroups gmane.os.netbsd.devel.security
Message-ID <[email protected]>
On 19.05.2020 18:00, Robert Elz wrote:
> Even with that, I still don't like overloading the result.

OK... how about the previous version of strscpy() from Linux.

static size_t strscpy(char *dest, const char *src, size_t size)
{
	size_t len = strnlen(src, size) + 1;
	if (len > size) {
		if (size)
			dest[0] = '\0';
		return 0;
	}
	memcpy(dest, src, len);
	return len;
}

https://github.com/torvalds/linux/commit/bceb7efa6a7e656bfaa67b6f54925e7db75bcd52

This one aborts on too long source. Would it match the NetBSD kernel needs?