Bug 14129 - [g77] gcc/f/lex.c buffer size limitation.
Summary: [g77] gcc/f/lex.c buffer size limitation.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 3.2.2
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2004-02-12 14:59 UTC by Valentine Kouznetsov
Modified: 2004-02-15 17:43 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-02-12 16:39:06


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Valentine Kouznetsov 2004-02-12 14:59:53 UTC
Hi,
fortran code crashed in preprocessor due to string hardcoded limit in gcc/f/lex.c.
When compiled in long path (more then 128 character long) compiler crashed. Here
example:

/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/tradcpp0 -lang-fortran -v
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/ZebraCommonsModule
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/include
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/.
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/include/.
-I/nfs/cleo3/cleo3_install/cleo3/Offline/rel/Jan13_04_P2/include
-I/nfs/cleo3/cleo3_install/cleo3/Offline/rel/Jan13_04_P2/include/.
-I/nfs/cleo3/cleo3_install/cleo3/Common/rel/Jan13_04_P2/include
-I/nfs/cleo3/cleo3_install/cleo3/Common/rel/Jan13_04_P2/include/i686-pc-linux-gnu
-I/nfs/cleo3/cleo3_install/cleo3/Offline/rel/Jan13_04_P2/other_sources
-D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=2 -D__GXX_ABI_VERSION=102
-D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__
-D__linux__ -D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1
-Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ -D__PIC__
-D__pic__ -DLinux -DCLEO_Linux -DDBCORBA -DMICOORB=2 -DMICOORB_MINOR=3
-DMICOORB_VERSION=7 -DHAVE_CONFIG_H
/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/ZebraCommonsModule/Fortran/forceCommonsLoad.F
> 1.tmp

This produce code 1.tmp which has:

# 1 "/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/ZebraCom
monsModule/Fortran/forceCommonsLoad.F"
      Subroutine forceCommonsLoad

# 1 "/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/ZebraCom
monsModule/ZebraCommonsModule/ZebraCommonsDeclarations.h" 1
C...Zebra memory allocation variables
C NWORD_GEANT - Number of words for Geant (separate Zebra bank ?)

Well preprocessor string exceed 128 characters, which are defined in
gcc/f/lex.c, see line 721

Then next step obviously crashed

/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/f771 -quiet -dumpbase
forceCommonsLoad.F -O -version -fno-second-underscore -finit-local-zero
-fno-automatic -fPIC
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/ZebraCommonsModule
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/include
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/.
-I/nfs/cleo3/cleo3_rpm/development_20040204/rpms/test/stand-alone/src/include/.
-I/nfs/cleo3/cleo3_install/cleo3/Offline/rel/Jan13_04_P2/include
-I/nfs/cleo3/cleo3_install/cleo3/Offline/rel/Jan13_04_P2/include/.
-I/nfs/cleo3/cleo3_install/cleo3/Common/rel/Jan13_04_P2/include
-I/nfs/cleo3/cleo3_install/cleo3/Common/rel/Jan13_04_P2/include/i686-pc-linux-gnu
-I/nfs/cleo3/cleo3_install/cleo3/Offline/rel/Jan13_04_P2/other_sources -o - <
1.tmp > 2.tmp

I think you need to follow POSIX rule and use PATH_MAX instead of hardcoded
(small) 128. On Linux PATH_MAX is quite big 4K, so if you don't follow POSIX
just increase buffer size to large value and if you hardcoded give people
compiler option to override it.

Here the patch:
vk@vklaptop(09:50:12)> diff gcc-3.2.2-20030225/gcc/f/lex.c
gcc-3.2.2-20030225/gcc/f/lex.c~
721,722c721
<   /*char buff[129];*/
<   char buff[PATH_MAX+1];
---
>   char buff[129];
976d974
<           /*
979,981d976
<       */
<       directive_buffer = (char *)xmalloc (PATH_MAX+1);
<       buffer_length = PATH_MAX+1;

which fix the problem.
Valentine.
Comment 1 Andrew Pinski 2004-02-12 16:39:05 UTC
Confirmed on the mainline and 3.4.0
Comment 2 GCC Commits 2004-02-15 14:27:17 UTC
Subject: Bug 14129

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-02-15 14:27:15

Modified files:
	gcc/f          : ChangeLog lex.c 

Log message:
	PR fortran/14129
	* lex.c (ffelex_cfelex_): Avoid calling xrealloc on a local stack
	allocated array.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/f/ChangeLog.diff?cvsroot=gcc&r1=1.627&r2=1.628
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/f/lex.c.diff?cvsroot=gcc&r1=1.45&r2=1.46

Comment 3 GCC Commits 2004-02-15 17:16:14 UTC
Subject: Bug 14129

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	sayle@gcc.gnu.org	2004-02-15 17:16:05

Modified files:
	gcc/f          : ChangeLog lex.c 

Log message:
	PR fortran/14129
	* lex.c (ffelex_cfelex_): Avoid calling xrealloc on a local stack
	allocated array.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/f/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.622.2.3&r2=1.622.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/f/lex.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.45&r2=1.45.10.1

Comment 4 Andrew Pinski 2004-02-15 17:43:33 UTC
Fixed.