From: Michael Snyder <msnyder@vmware.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [commit] objc-lang.c: avoid string overrun
Date: Mon, 28 Feb 2011 18:02:00 -0000 [thread overview]
Message-ID: <4D6BE2BD.4070608@vmware.com> (raw)
In-Reply-To: <20110228045034.GB12861@host1.dyn.jankratochvil.net>
Jan Kratochvil wrote:
> Hi Michael,
>
> On Mon, 28 Feb 2011 03:15:47 +0100, Michael Snyder wrote:
>> --- objc-lang.c 10 Jan 2011 20:38:49 -0000 1.91
>> +++ objc-lang.c 28 Feb 2011 02:13:37 -0000
> char myregexp[2048];
>> @@ -720,7 +720,7 @@ selectors_info (char *regexp, int from_t
>> strcpy(myregexp, ".*]");
>> else
>> {
>> - strcpy(myregexp, regexp);
>> + strncpy(myregexp, regexp, sizeof (myregexp) - 1);
>> if (myregexp[strlen(myregexp) - 1] == '$') /* end of selector */
>> myregexp[strlen(myregexp) - 1] = ']'; /* end of method name */
>> else
>
> I agree it fixes a bug. But still if the limit applies then the immediately
> following strlen will read uninitialized memory myregexp[2047].
>
> Do you agree with this fix instead?
>
> (Yes, the code should be completely different but we fix only bugs now.)
OK, please apply.
> gdb/
> 2011-02-28 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> * objc-lang.c (selectors_info): Error on too long REGEXP.
>
> --- a/gdb/objc-lang.c
> +++ b/gdb/objc-lang.c
> @@ -720,7 +720,9 @@ selectors_info (char *regexp, int from_tty)
> strcpy(myregexp, ".*]");
> else
> {
> - strncpy(myregexp, regexp, sizeof (myregexp) - 1);
> + if (sizeof (myregexp) < strlen (regexp) + 1)
> + error (_("Regexp is too long: %s"), regexp);
> + strcpy(myregexp, regexp);
> if (myregexp[strlen(myregexp) - 1] == '$') /* end of selector */
> myregexp[strlen(myregexp) - 1] = ']'; /* end of method name */
> else
next prev parent reply other threads:[~2011-02-28 18:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-28 4:10 Michael Snyder
2011-02-28 4:52 ` Jan Kratochvil
2011-02-28 18:02 ` Michael Snyder [this message]
2011-02-28 18:15 ` Jan Kratochvil
2011-02-28 12:21 ` Pedro Alves
2011-02-28 18:27 ` Michael Snyder
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=4D6BE2BD.4070608@vmware.com \
--to=msnyder@vmware.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.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