public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "liftdat at protonmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug pch/105403] New: [Bug] Buffer overflow can happen when reading pchf_data from file Date: Wed, 27 Apr 2022 07:10:20 +0000 [thread overview] Message-ID: <bug-105403-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105403 Bug ID: 105403 Summary: [Bug] Buffer overflow can happen when reading pchf_data from file Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: pch Assignee: unassigned at gcc dot gnu.org Reporter: liftdat at protonmail dot com Target Milestone: --- In the file libcpp/files.c, the function _cpp_read_file_entries has the following code (link: https://github.com/gcc-mirror/gcc/blob/9715f10c0651c9549b479b69d67be50ac4bd98a6/libcpp/files.cc#L2049): bool _cpp_read_file_entries (cpp_reader *pfile ATTRIBUTE_UNUSED, FILE *f) { struct pchf_data d; if (fread (&d, sizeof (struct pchf_data) - sizeof (struct pchf_entry), 1, f) != 1) return false; pchf = XNEWVAR (struct pchf_data, sizeof (struct pchf_data) + sizeof (struct pchf_entry) * (d.count - 1)); memcpy (pchf, &d, sizeof (struct pchf_data) - sizeof (struct pchf_entry)); if (fread (pchf->entries, sizeof (struct pchf_entry), d.count, f) != d.count) return false; return true; } The count field for the pchf_data d is read from the file f. Therefore, given a crafted input, d.count can get a really large value, e.g., UINT64_MAX. In this case, the computation of the allocation size will trigger an integer overflow and give a small value for the size of the allocated buffer: sizeof (struct pchf_data) + sizeof (struct pchf_entry) * (d.count - 1) This can lead to subsequent buffer overflow for the buffer pointed by pchf.
next reply other threads:[~2022-04-27 7:10 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-27 7:10 liftdat at protonmail dot com [this message] 2022-04-27 10:37 ` [Bug pch/105403] " geoffk at geoffk dot org 2022-04-28 7:08 ` liftdat at protonmail dot com
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-105403-4@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).