Bug 11733 - Out of bounds array access prevents build.
Summary: Out of bounds array access prevents build.
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.20
: P2 minor
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-21 05:00 UTC by Forest Belton
Modified: 2010-06-21 08:01 UTC (History)
1 user (show)

See Also:
Host: i686-pc-mingw32
Target: sh4-unknown-elf
Build: sh4-unknown-elf
Last reconfirmed: 2010-06-21 08:00:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Forest Belton 2010-06-21 05:00:10 UTC
When compiling binutils for the sh4-elf target, the following error occurs:

../../src/binutils-2.20.1/gas/config/tc-sh.c: In function 'find_cooked_opcode':
../../src/binutils-2.20.1/gas/config/tc-sh.c:2540:7: error: array subscript is 
above array bounds

Upon closer inspection, it seems to be due to the line: name[nlen] = 0;

name is declared as a char[20], and the previous for loop describes name < 20 as 
one of the predicates.

A fix for this would involve either changing name to be a char[21] instead, or 
perhaps changing the predicate in the loop to be name < (sizeof (name) - 1). I'm 
not familiar enough with the binutils source to comment on which would be the 
more suitable option.
Comment 1 Forest Belton 2010-06-21 05:03:58 UTC
Note: I'm using gcc 4.5.0 to compile binutils. I strongly suspect that this sort 
of check was only added recently, as I've compiled binutils for sh4-elf before 
without issue.
Comment 2 Sourceware Commits 2010-06-21 07:43:07 UTC
Subject: Bug 11733

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2010-06-21 07:42:55

Modified files:
	gas            : ChangeLog 
	gas/config     : tc-sh.c 

Log message:
	PR gas/11733
	* config/tc-sh.c (find_cooked_opcode): Correct array bounds check.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/ChangeLog.diff?cvsroot=src&r1=1.4172&r2=1.4173
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-sh.c.diff?cvsroot=src&r1=1.137&r2=1.138

Comment 3 Alan Modra 2010-06-21 08:01:15 UTC
Fixed mainline