Bug 12014 - strcpy used with overlapping arguments
Summary: strcpy used with overlapping arguments
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-08-21 17:45 UTC by Herman ten Brugge
Modified: 2015-09-17 13:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-08-21 18:02:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Herman ten Brugge 2003-08-21 17:45:57 UTC
I just ran bounds-checking on the gcc-3.3.1 release. It produced an error in 
adadecode.c. The problem is that it contains code like:

strcpy (ada_name, ada_name + 5);
strcpy (tktoken, tktoken + 2);
strcpy (ada_name + k + 1, ada_name + k + 2);

All of these strcpy's are illegal because the source and destination pointer
overlap.
Comment 1 Andrew Pinski 2003-08-21 18:02:50 UTC
The ada front-end is the worst front-end I have ever seen in terms of problems.
I can confirm these still exists on the mainline.
Comment 2 GCC Commits 2003-10-24 13:02:46 UTC
Subject: Bug 12014

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	charlet@gcc.gnu.org	2003-10-24 13:02:42

Modified files:
	gcc/ada        : adadecode.c exp_disp.adb g-catiio.adb make.adb 
	                 Makefile.generic prj-env.adb prj-env.ads 
	                 sem_ch12.adb sem_ch3.adb sem_ch3.ads 
	                 adadecode.h atree.h elists.h nlists.h raise.h 
	                 Make-lang.in 

Log message:
	* adadecode.c (ostrcpy): New function.
	(__gnat_decode): Use ostrcpy of strcpy.
	(has_prefix): Set first parameter a const.
	(has_suffix): Set first parameter a const.
	Update copyright notice. Fix source name in header.
	Removes a trailing space.
	PR ada/12014.
	
	* exp_disp.adb:
	Remove the test against being in No_Run_Time_Mode before generating a
	call to Register_Tag. It is redundant with the test against the
	availability of the function Register_Tag.
	
	* g-catiio.adb: (Month_Name): Correct spelling of February
	
	* make.adb: (Mains): New package
	(Initialize): Call Mains.Delete
	(Gnatmake): Check that each main on the command line is a source of a
	project file and, if there are several mains, each of them is a source
	of the same project file.
	(Gnatmake): When a foreign language is specified in attribute Languages,
	no main is specified on the command line and attribute Mains is not
	empty, only build the Ada main. If there is no Ada main, just compile
	the Ada sources and their closure.
	(Gnatmake): If a main is specified on the command line with directory
	information, check that the source exists and, if it does, that the path
	is the actual path of a source of a project.
	
	* prj-env.adb:
	(File_Name_Of_Library_Unit_Body): New Boolean parameter Full_Path. When
	Full_Path is True, return the full path instead of the simple file name.
	(Project_Of): New function
	
	* prj-env.ads:
	(File_Name_Of_Library_Unit_Body): New Boolean parameter Full_Path,
	defaulted to False.
	(Project_Of): New function
	
	* Makefile.generic:
	Ensure objects of main project are always checked and rebuilt if needed.
	Set CC to gcc by default.
	Prepare new handling of link by creating a global archive (not activated
	yet).
	
	* adadecode.h, atree.h, elists.h, nlists.h, raise.h,
	stringt.h: Update copyright notice. Remove trailing blanks.
	Fix source name in header.
	
	* sem_ch12.adb: Minor reformatting
	
	* sem_ch3.adb:
	Minor reformatting (including new function return style throughout)
	
	* sem_ch3.ads:
	Minor reformatting (including new function return style throughout)
	
	* Make-lang.in: Makefile automatically updated

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/adadecode.c.diff?cvsroot=gcc&r1=1.5&r2=1.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/exp_disp.adb.diff?cvsroot=gcc&r1=1.5&r2=1.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/g-catiio.adb.diff?cvsroot=gcc&r1=1.4&r2=1.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/make.adb.diff?cvsroot=gcc&r1=1.17&r2=1.18
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/Makefile.generic.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/prj-env.adb.diff?cvsroot=gcc&r1=1.10&r2=1.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/prj-env.ads.diff?cvsroot=gcc&r1=1.8&r2=1.9
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/sem_ch12.adb.diff?cvsroot=gcc&r1=1.22&r2=1.23
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/sem_ch3.adb.diff?cvsroot=gcc&r1=1.19&r2=1.20
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/sem_ch3.ads.diff?cvsroot=gcc&r1=1.7&r2=1.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/adadecode.h.diff?cvsroot=gcc&r1=1.5&r2=1.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/atree.h.diff?cvsroot=gcc&r1=1.6&r2=1.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/elists.h.diff?cvsroot=gcc&r1=1.6&r2=1.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/nlists.h.diff?cvsroot=gcc&r1=1.6&r2=1.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/raise.h.diff?cvsroot=gcc&r1=1.6&r2=1.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ada/Make-lang.in.diff?cvsroot=gcc&r1=1.43&r2=1.44

Comment 3 Arnaud Charlet 2003-10-24 13:06:25 UTC
Fixed in mainline.
I'm not 100% happy with the fix, but at least the current code won't overlap.

Arno