public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/fix-ubsan-opts-global.cc)] Fix ubsan error in opts-global.cc
@ 2022-05-16  7:50 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2022-05-16  7:50 UTC (permalink / raw)
  To: gcc-cvs

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))


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-16  7:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16  7:50 [gcc(refs/users/marxin/heads/fix-ubsan-opts-global.cc)] Fix ubsan error in opts-global.cc Martin Liska

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).