From: Johan Hedberg <johan.hedberg@gmail.com>
To: Radoslaw Jablonski <radoslawjablonski@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH obexd] Fix writing out of bounds in add_slash func
Date: Tue, 26 Jul 2011 14:25:16 +0300 [thread overview]
Message-ID: <20110726112516.GB10285@dell> (raw)
In-Reply-To: <1311232939-32431-1-git-send-email-radoslawjablonski@gmail.com>
Hi Radek,
On Thu, Jul 21, 2011, Radoslaw Jablonski wrote:
> diff --git a/plugins/vcard.c b/plugins/vcard.c
> index b997fc4..a6eb5f5 100644
> --- a/plugins/vcard.c
> +++ b/plugins/vcard.c
> @@ -101,27 +101,41 @@ static void add_slash(char *dest, const char *src, int len_max, int len)
> {
> int i, j;
>
> - for (i = 0, j = 0; i < len && j < len_max; i++, j++) {
> + for (i = 0, j = 0; i < len && j < len_max - 1; i++, j++) {
> + /* filling dest buffer - last field need to be reserved
> + * for '\0'*/
> switch (src[i]) {
> case '\n':
> + if (j == len_max - 2)
> + /* not enough space in the buffer to put char
> + * preceded with escaping sequence */
> + goto done;
I think it'd be more robust and clear that you're testing for an upper
limit to have a > or >= comparison here and in the other places, e.g.
if (j + 2 >= len_max)
> +done:
> dest[j] = 0;
> - return;
> }
The return statement removal is a code cleanup which should be in its
own patch.
Johan
prev parent reply other threads:[~2011-07-26 11:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-21 7:22 [PATCH obexd] Fix writing out of bounds in add_slash func Radoslaw Jablonski
2011-07-26 11:25 ` Johan Hedberg [this message]
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=20110726112516.GB10285@dell \
--to=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=radoslawjablonski@gmail.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