Bug 103893 - ada demangler heap overflow
Summary: ada demangler heap overflow
Status: RESOLVED DUPLICATE of bug 92453
Alias: None
Product: gcc
Classification: Unclassified
Component: demangler (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-03 01:59 UTC by Alan Modra
Modified: 2022-01-03 02:18 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2022-01-03 01:59:07 UTC
From https://sourceware.org/bugzilla/show_bug.cgi?id=28736

valgrind c++filt -s gnat vfffffSO__fffSO

==1573233== Invalid write of size 1
==1573233==    at 0x4848DCC: strcpy (vg_replace_strmem.c:523)
==1573233==    by 0x72688C: ada_demangle (cplus-dem.c:338)
==1573233==    by 0x726ABA: cplus_demangle (cplus-dem.c:187)
==1573233==    by 0x4038E8: demangle_it (cxxfilt.c:66)
==1573233==    by 0x403AEC: main (cxxfilt.c:203)
==1573233==  Address 0x4a60057 is 0 bytes after a block of size 23 alloc'd
==1573233==    at 0x4842839: malloc (vg_replace_malloc.c:380)
==1573233==    by 0x737A6B: xmalloc (xmalloc.c:147)
==1573233==    by 0x726617: ada_demangle (cplus-dem.c:223)
==1573233==    by 0x726ABA: cplus_demangle (cplus-dem.c:187)
==1573233==    by 0x4038E8: demangle_it (cxxfilt.c:66)
==1573233==    by 0x403AEC: main (cxxfilt.c:203)

The following comment in cplus-dem.c:ada_demangle is false for fuzzed input, specifically the part that says "they occur only once".

  /* Most of the demangling will trivially remove chars.  Operator names
     may add one char but because they are always preceeded by '__' which is
     replaced by '.', they eventually never expand the size.
     A few special names such as '___elabs' add a few chars (at most 7), but
     they occur only once.  */
  len0 = strlen (mangled) + 7 + 1;
  demangled = XNEWVEC (char, len0);
Comment 1 Andrew Pinski 2022-01-03 02:18:19 UTC
Dup of bug 92453. A patch was posted even.

*** This bug has been marked as a duplicate of bug 92453 ***