Skip to content

Commit f1ec39c

Browse files
committed
d: fix ASAN in option processing
Fixes: ==129444==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000666ca5c at pc 0x000000ef094b bp 0x7fffffff8180 sp 0x7fffffff8178 READ of size 4 at 0x00000666ca5c thread T0 #0 0xef094a in parse_optimize_options ../../gcc/d/d-attribs.cc:855 #1 0xef0d36 in d_handle_optimize_attribute ../../gcc/d/d-attribs.cc:916 #2 0xef107e in d_handle_optimize_attribute ../../gcc/d/d-attribs.cc:887 #3 0xff85b1 in decl_attributes(tree_node**, tree_node*, int, tree_node*) ../../gcc/attribs.c:829 #4 0xef2a91 in apply_user_attributes(Dsymbol*, tree_node*) ../../gcc/d/d-attribs.cc:427 gcc-mirror#5 0xf7b7f3 in get_symbol_decl(Declaration*) ../../gcc/d/decl.cc:1346 gcc-mirror#6 0xf87bc7 in get_symbol_decl(Declaration*) ../../gcc/d/decl.cc:967 gcc-mirror#7 0xf87bc7 in DeclVisitor::visit(FuncDeclaration*) ../../gcc/d/decl.cc:808 gcc-mirror#8 0xf83db5 in DeclVisitor::build_dsymbol(Dsymbol*) ../../gcc/d/decl.cc:146 for the following test-case: gcc/testsuite/gdc.dg/attr_optimize1.d. gcc/d/ChangeLog: * d-attribs.cc (parse_optimize_options): Check index before accessing cl_options.
1 parent 2cadaa1 commit f1ec39c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

gcc/d/d-attribs.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ parse_optimize_options (tree args)
852852
unsigned j = 1;
853853
for (unsigned i = 1; i < decoded_options_count; ++i)
854854
{
855-
if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION))
855+
unsigned opt_index = decoded_options[i].opt_index;
856+
if (opt_index >= cl_options_count
857+
&& ! (cl_options[opt_index].flags & CL_OPTIMIZATION))
856858
{
857859
ret = false;
858860
warning (OPT_Wattributes,

0 commit comments

Comments
 (0)