From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Michael Snyder <msnyder@vmware.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [commit] objc-lang.c: avoid string overrun
Date: Mon, 28 Feb 2011 04:52:00 -0000 [thread overview]
Message-ID: <20110228045034.GB12861@host1.dyn.jankratochvil.net> (raw)
In-Reply-To: <4D6B0553.6010803@vmware.com>
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.)
Thanks,
Jan
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 4:50 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 [this message]
2011-02-28 18:02 ` Michael Snyder
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=20110228045034.GB12861@host1.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=msnyder@vmware.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