public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.cc?
@ 2001-09-24  6:27 Hans-Peter Nilsson
  2001-09-24  6:44 ` Rick Copeland
  2001-09-24  7:20 ` Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.c Greg Hosler
  0 siblings, 2 replies; 4+ messages in thread
From: Hans-Peter Nilsson @ 2001-09-24  6:27 UTC (permalink / raw)
  To: gcc; +Cc: libstdc++

Is this some C++ gotcha or is there an obvious buffer-overwrite
here?  The CRIS gcc port and the simulator dump says the buffer
is overwritten, but there's no absolute truth in that.

 ...
  const char* ccarray1 = "san francisco roof garden inspectors";
  const char* ccarray2 = "san francisco sunny-day park inspectors";
  char carray[30];
  std::strcpy(carray, ccarray1);
 ...

Will trade patch for clue.

brgds, H-P

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.cc?
  2001-09-24  6:27 Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.cc? Hans-Peter Nilsson
@ 2001-09-24  6:44 ` Rick Copeland
  2001-09-24  7:20 ` Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.c Greg Hosler
  1 sibling, 0 replies; 4+ messages in thread
From: Rick Copeland @ 2001-09-24  6:44 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: gcc, libstdc++

Well, since strlen(ccarray1) == 36, and you're copying into a 30-byte 
array, it looks like an obvious buffer-overflow [write?].

Hans-Peter Nilsson wrote:

>Is this some C++ gotcha or is there an obvious buffer-overwrite
>here?  The CRIS gcc port and the simulator dump says the buffer
>is overwritten, but there's no absolute truth in that.
>
> ...
>  const char* ccarray1 = "san francisco roof garden inspectors";
>  const char* ccarray2 = "san francisco sunny-day park inspectors";
>  char carray[30];
>  std::strcpy(carray, ccarray1);
> ...
>
>Will trade patch for clue.
>
>brgds, H-P
>
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.c
  2001-09-24  6:27 Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.cc? Hans-Peter Nilsson
  2001-09-24  6:44 ` Rick Copeland
@ 2001-09-24  7:20 ` Greg Hosler
  2001-09-24  7:37   ` Hans-Peter Nilsson
  1 sibling, 1 reply; 4+ messages in thread
From: Greg Hosler @ 2001-09-24  7:20 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: libstdc++, gcc

On 24-Sep-2001 Hans-Peter Nilsson wrote:
> Is this some C++ gotcha or is there an obvious buffer-overwrite
> here?  The CRIS gcc port and the simulator dump says the buffer
> is overwritten, but there's no absolute truth in that.
> 
>  ...
>   const char* ccarray1 = "san francisco roof garden inspectors";
>   const char* ccarray2 = "san francisco sunny-day park inspectors";
>   char carray[30];
>   std::strcpy(carray, ccarray1);
>  ...
> 
> Will trade patch for clue.

how do you fit 37 characters (i.e. strlen(ccarray1) + 1 for the null)
into 30 char buffer (size of carray), without overflowing it ?

-G

+---------------------------------------------------------------------+
   You can release software that's good, software that's inexpensive, or
   software that's available on time.  You can usually release software
   that has 2 of these 3 attributes -- but not all 3.
| Greg Hosler                                   hosler@lugs.org.sg    |
+---------------------------------------------------------------------+

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.c
  2001-09-24  7:20 ` Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.c Greg Hosler
@ 2001-09-24  7:37   ` Hans-Peter Nilsson
  0 siblings, 0 replies; 4+ messages in thread
From: Hans-Peter Nilsson @ 2001-09-24  7:37 UTC (permalink / raw)
  To: hosler; +Cc: hans-peter.nilsson, libstdc++, gcc

> Date: Mon, 24 Sep 2001 22:24:35 +0800 (SGT)
> From: Greg Hosler <hosler@lugs.org.sg>

> On 24-Sep-2001 Hans-Peter Nilsson wrote:
> > Is this some C++ gotcha or is there an obvious buffer-overwrite
> > here?  The CRIS gcc port and the simulator dump says the buffer
> > is overwritten, but there's no absolute truth in that.
> > 
> >  ...
> >   const char* ccarray1 = "san francisco roof garden inspectors";
> >   const char* ccarray2 = "san francisco sunny-day park inspectors";
> >   char carray[30];
> >   std::strcpy(carray, ccarray1);
> >  ...
> > 
> > Will trade patch for clue.
> 
> how do you fit 37 characters (i.e. strlen(ccarray1) + 1 for the null)
> into 30 char buffer (size of carray), without overflowing it ?

That's the question I'm asking.  But presumably some corner in
that pile of papers called a C++ standards document could
interpret to say that strcpy should "DWIM" here.  Anyway, since
now two people see the same thing I do, enough said.

brgds, H-P

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-09-24  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-24  6:27 Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.cc? Hans-Peter Nilsson
2001-09-24  6:44 ` Rick Copeland
2001-09-24  7:20 ` Buffer overwrite in libstdc++-v3 test 21_strings/c_strings.c Greg Hosler
2001-09-24  7:37   ` Hans-Peter Nilsson

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 read-only IMAP folder(s) and NNTP newsgroup(s).