Bug 23940

Summary: check index is within bounds before using it
Product: binutils Reporter: wuheng <wu.heng>
Component: gasAssignee: Alan Modra <amodra>
Status: RESOLVED FIXED    
Severity: normal CC: ppluzhnikov, wu.heng
Priority: P2    
Version: 2.32   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2019-01-25 00:00:00
Attachments: check bounds befroe using
bug file to reproduce the error

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