Bug 23940 - check index is within bounds before using it
Summary: check index is within bounds before using it
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-30 09:19 UTC by wuheng
Modified: 2019-08-02 10:40 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-01-25 00:00:00


Attachments
check bounds befroe using (235 bytes, patch)
2018-11-30 09:19 UTC, wuheng
Details | Diff
bug file to reproduce the error (536 bytes, text/plain)
2018-12-04 12:14 UTC, wuheng
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wuheng 2018-11-30 09:19:34 UTC
Created attachment 11422 [details]
check bounds befroe using

The var "idx" should be checked before using in function "getstring" gas/macro.c:288.

	  while ((in->ptr[idx] != '>' || nest)
		 && idx < in->len)

The out of bounds judgment should be in front of using.
Comment 1 wuheng 2018-12-04 12:14:42 UTC
Created attachment 11429 [details]
bug file to reproduce the error

the bound of char* "in->ptr" should be checked first before using!
Comment 2 cvs-commit@gcc.gnu.org 2019-01-25 04:31:34 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=10c172ba93dde7cb7c46982ca217e646565bf938

commit 10c172ba93dde7cb7c46982ca217e646565bf938
Author: Wu Heng <wu.heng@zte.com.cn>
Date:   Fri Jan 25 13:41:47 2019 +1030

    PR23940, check bounds before using
    
    	PR gas/23940
    	* macro.c (getstring): Check array bound before accessing.
Comment 3 cvs-commit@gcc.gnu.org 2019-08-02 10:40:19 UTC
The binutils-2_32-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c856219bcaedba3e00f9875e01957fe64a3c3d58

commit c856219bcaedba3e00f9875e01957fe64a3c3d58
Author: Wu Heng <wu.heng@zte.com.cn>
Date:   Fri Jan 25 13:41:47 2019 +1030

    PR23940, check bounds before using
    
    	PR gas/23940
    	* macro.c (getstring): Check array bound before accessing.
    
    (cherry picked from commit 10c172ba93dde7cb7c46982ca217e646565bf938)
Comment 4 Alan Modra 2019-08-02 10:40:58 UTC
Fixed