public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/fix-ubsan-opts-global.cc)] Fix ubsan error in opts-global.cc Date: Mon, 16 May 2022 07:50:01 +0000 (GMT) [thread overview] Message-ID: <20220516075001.C60AD3857C6F@sourceware.org> (raw) https://gcc.gnu.org/g:7b43fcd2310b981b0c6a042b6fed45d12346b8c4 commit 7b43fcd2310b981b0c6a042b6fed45d12346b8c4 Author: Martin Liska <mliska@suse.cz> Date: Mon May 16 09:48:27 2022 +0200 Fix ubsan error in opts-global.cc Fixes: opts-global.cc:75:15: runtime error: store to address 0x00000bc9be70 with insufficient space for an object of type 'char' which happens when mask == 0, len == 0 and we allocate zero elements. Eventually, result[0] is called which triggers the UBSAN. gcc/ChangeLog: * opts-global.cc (write_langs): Allocate at least one byte. Diff: --- gcc/opts-global.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/opts-global.cc b/gcc/opts-global.cc index a18c76940f9..4f5f8cdcb98 100644 --- a/gcc/opts-global.cc +++ b/gcc/opts-global.cc @@ -61,7 +61,7 @@ write_langs (unsigned int mask) if (mask & (1U << n)) len += strlen (lang_name) + 1; - result = XNEWVEC (char, len); + result = XNEWVEC (char, MAX (1, len)); len = 0; for (n = 0; (lang_name = lang_names[n]) != 0; n++) if (mask & (1U << n))
reply other threads:[~2022-05-16 7:50 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220516075001.C60AD3857C6F@sourceware.org \ --to=marxin@gcc.gnu.org \ --cc=gcc-cvs@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).