From: Ben Collins <bcollins@debian.org>
To: Ren? Scharfe <l.s.r@web.de>
Cc: Linus Torvalds <torvalds@transmeta.com>,
Edgar Toernig <froese@gmx.de>,
linux-kernel@vger.kernel.org
Subject: Re: Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE
Date: Sun, 25 May 2003 14:16:22 -0400 [thread overview]
Message-ID: <20030525181622.GD602@phunnypharm.org> (raw)
In-Reply-To: <20030525210509.09429aaa.l.s.r@web.de>
On Sun, May 25, 2003 at 09:05:09PM +0200, Ren? Scharfe wrote:
> On Sun, 25 May 2003 19:24:40 +0200 Edgar Toernig <froese@gmx.de> wrote:
> > Ren? Scharfe wrote:
> > > + if (bufsize == 0)
> > > + return 0;
> >
> > return ret; ???
>
> Yes, Samba's and the BSDs' strlcpy() deviate in that point. It's a very
> unusual case to have a zero-sized buffer, though, so probably it doesn't
> matter much.
>
> Anyway, I corrected this. Patch below contains a "BSD-compatible" version,
> and also a strlcat().
>
> Ben, I think this one is better than your's because it's shorter and
> already GPL'd (there's not more license than C code :). Linus?
> +size_t strlcat(char *dest, const char *src, size_t bufsize)
> +{
> + size_t len1 = strlen(dest);
> + size_t len2 = strlen(src);
> + size_t ret = len1 + len2;
> +
> + if (len1+len2 >= bufsize)
> + len2 = bufsize - (len1+1);
> + if (len2 > 0) {
> + memcpy(dest+len1, src, len2);
> + dest[len1+len2] = '\0';
> + }
> + return ret;
> +}
> +#endif
Your strlcat doesn't take into consideration that a zero bufsize could
mean that dest is not NUL-terminated, in which case strlen(dest) could
blow up in your face. Since strlcpy can handle zero bufsize, strlcat
should be able to handle being called just after strlcpy being called
with zero bufsize (see my patch).
I personally am not concerned either way, but it is definitely worth
noting.
--
Debian - http://www.debian.org/
Linux 1394 - http://www.linux1394.org/
Subversion - http://subversion.tigris.org/
Deqo - http://www.deqo.com/
next prev parent reply other threads:[~2003-05-25 18:52 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-25 9:21 Resend [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE René Scharfe
2003-05-25 12:05 ` Christoph Hellwig
2003-05-25 17:24 ` Edgar Toernig
2003-05-25 19:05 ` René Scharfe
2003-05-25 18:16 ` Ben Collins [this message]
2003-05-25 20:11 ` René Scharfe
2003-05-25 19:01 ` Valdis.Kletnieks
2003-05-25 19:31 ` René Scharfe
2003-05-26 1:13 ` Linus Torvalds
2003-05-26 13:29 ` [RFC] [2.5 patch] Change strlcpy and strlcat Adrian Bunk
2003-05-26 14:10 ` Ben Collins
2003-05-26 17:11 ` Linus Torvalds
-- strict thread matches above, loose matches on Subject: below --
2003-05-13 7:14 [PATCH] Make KOBJ_NAME_LEN match BUS_ID_SIZE Ben Collins
2003-05-13 15:08 ` Patrick Mochel
2003-05-16 0:20 ` Resend " Ben Collins
2003-05-16 18:43 ` Felipe Alfaro Solana
2003-05-25 0:07 ` Ben Collins
2003-05-25 3:52 ` Linus Torvalds
2003-05-25 3:10 ` Ben Collins
2003-05-25 12:03 ` Adam Sampson
2003-05-25 17:10 ` Linus Torvalds
2003-05-25 16:40 ` Ben Collins
2003-05-25 15:51 ` Matt Mackall
2003-05-25 17:25 ` Riley Williams
2003-05-25 18:13 ` Valdis.Kletnieks
2003-05-25 23:42 ` Matt Mackall
2003-05-25 16:41 ` Ben Collins
2003-07-11 9:50 ` Rogier Wolff
2003-05-25 8:02 ` Russell King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030525181622.GD602@phunnypharm.org \
--to=bcollins@debian.org \
--cc=froese@gmx.de \
--cc=l.s.r@web.de \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).