Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jul 1999 00:15:31 +0200
From:      Sheldon Hearn <sheldonh@uunet.co.za>
To:        Garance A Drosihn <drosih@rpi.edu>
Cc:        Paul Hart <hart@iserver.com>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: OpenBSD's strlcpy(3) and strlcat(3) 
Message-ID:  <79492.932076931@axl.noc.iafrica.com>
In-Reply-To: Your message of "Thu, 15 Jul 1999 17:33:29 -0400." <v04011702b3b3f07b38ae@[128.113.24.47]> 

next in thread | previous in thread | raw e-mail | index | archive | help

[Hijacked from freebsd-security]

On Thu, 15 Jul 1999 17:33:29 -0400, Garance A Drosihn wrote:

> What I wanted to do was have "estr" routines, where the destination
> is specified as the starting point and the ending point of the area
> available for the string (as two parameters).  The routines would
> return the position of the current string-terminator.  So you could
> do things like:

As I understand it, the goal here is to return to the caller the number
of bytes copied (however you represent it), so that the caller can
easily determine whether or not dst is safe for operations demanding a
null-terminated string.

If that is true, then I think the interface you propose is overly
complex. Looking at the existing functions, their only flaw is that they
return known (and therefore useless) information, "wasting" the return
value. All we need is:

size_t
foocpy(char *dst, const char *src)

size_t
fooncpy(char *dst, const char *src, size_t len)

size_t
foocat(char *s, const char *append)

size_t
fooncat(char *s, const char *append, size_t count)

where the return value is the number of bytes {copied,appended}.

Since the goal is simply to make it easier to do what is already
possible, I think that this approach is better than what you're
suggesting, since the pointer arithmetic required in the caller is
simpler.

And since the prototypes for fooncpy and fooncat above match exactly
those of the proposed strlcpy and strlcat respectively (just had a
look before I "hit the send button"), I'd say that the latter two are
definitely the functions you want.

Ciao,
Sheldon.


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




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