public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ronghua at iu dot edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105115] `demangle_const` causes infinite recursion and stack overflow Date: Tue, 17 May 2022 20:44:54 +0000 [thread overview] Message-ID: <bug-105115-4-zRTsLfTzdf@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-105115-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105115 --- Comment #2 from ronghua at iu dot edu --- The simplified PoC: $ echo _RYAbB2_ | ./binutils/cxxfilt Segmentation fault Root Cause Analysis: 1. In `rust_demangle_callback`, "_R" at beginning causes `rdm.version == 0`[1][2], so `demangle_path` in the else-branch is called[3] with `rdm.sym == "YAbB2_"`, with `rdm.next` field initialized to 0. 2. Next char 'Y' causes `demangle_type` to be called[4] in a switch-case branch, with `rdm.next == 1`. 3. Next char 'A' causes `demangle_type` to be called first[5] to consume char 'b', then `demangle_const` is called[6] with `rdm.next == 3`. 4. Next char 'B' is consumed[7], and "2_" is parsed as `integer_62`[8] to be value 3, and this vlaue is assigned to `rdm.next`, then `demangle_const` is called recursively[9]. However, currently the situation is `rdm.next == 3` again, which is exactly same as last call to `demangle_const`, and this causes infinite recursion. [1] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1356 [2] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1362 [3] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1453 [4] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L759 [5] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L934 [6] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L938 [7] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1151 [8] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1153 [9] https://github.com/bminor/binutils-gdb/blob/626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1158 Possible Fix: The infinite recursion check added in this [commit](https://github.com/bminor/binutils-gdb/commit/f10f8617a302f45dae721eae0cd659911f03d864) should also be applied to `demangle_const`
prev parent reply other threads:[~2022-05-17 20:44 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-31 0:32 [Bug c++/105115] New: " ronghua at iu dot edu 2022-05-17 18:22 ` [Bug c++/105115] " ronghua at iu dot edu 2022-05-17 20:44 ` ronghua at iu dot edu [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=bug-105115-4-zRTsLfTzdf@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /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: linkBe 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; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).