This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Ada] Move and rename max_path_len
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 19 May 2002 23:40:36 +0200
- Subject: [Ada] Move and rename max_path_len
The following change prepares fixing the buffer overflow bug in
adaint.c:__gnat_tmp_name(). We need to access max_path_len in this
file, but cstreams.c is not always linked in, that's why I moved it to
adaint.c. In addition, max_path_len is in the user namespace, which
is a no-no for such an identifier, that's why I prepended "__gnat_".
Note that POSIX does not require that an upper bound for the path name
length exists, so all code that uses __gnat_max_path_len is inherently
unportable. Each time we pass a path name from C to Ada, we should
probably use malloc()ed storage some day.
2002-05-19 Florian Weimer <fw@deneb.enyo.de>
* cstreams.c (max_path_len): Move from here ...
* adaint.c (__gnat_max_path_len): ... to here.
* adaint.c (__gnat_max_path_len): Declare.
* g-dirope.adb (Max_Path): Adjust.
* g-os_lib.adb (Normalize_Pathname.Max_Path): Adjust.
* i-cstrea.ads (max_path_len): Adjust.
* osint.adb (Get_RTS_Search_Dir.Max_Path): Adjust.
* xr_tabls.adb (Dir_Name.Max_Path: Adjust.
Index: adaint.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/adaint.c,v
retrieving revision 1.9
diff -c -r1.9 adaint.c
*** adaint.c 14 Mar 2002 10:59:01 -0000 1.9
--- adaint.c 19 May 2002 21:28:46 -0000
***************
*** 213,218 ****
--- 213,236 ----
const int __gnat_vmsp = 0;
#endif
+ /* This variable is used to export the maximum length of a path name to
+ Ada code. */
+
+ #ifdef __EMX__
+ int __gnat_max_path_len = _MAX_PATH;
+
+ #elif defined (VMS)
+ int __gnat_max_path_len = 4096; /* PATH_MAX */
+
+ #elif defined (__vxworks) || defined (__OPENNT)
+ int __gnat_max_path_len = PATH_MAX;
+
+ #else
+ #include <sys/param.h>
+ int __gnat_max_path_len = MAXPATHLEN;
+
+ #endif
+
/* The following macro HAVE_READDIR_R should be defined if the
system provides the routine readdir_r. */
#undef HAVE_READDIR_R
Index: adaint.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/adaint.h,v
retrieving revision 1.7
diff -c -r1.7 adaint.h
*** adaint.h 14 Mar 2002 10:59:01 -0000 1.7
--- adaint.h 19 May 2002 21:28:46 -0000
***************
*** 33,38 ****
--- 33,39 ----
#include <dirent.h>
+ extern int __gnat_max_path_len;
extern void __gnat_to_gm_time PARAMS ((int *, int *,
int *, int *,
int *, int *,
Index: cstreams.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/cstreams.c,v
retrieving revision 1.4
diff -c -r1.4 cstreams.c
*** cstreams.c 14 Mar 2002 10:59:06 -0000 1.4
--- cstreams.c 19 May 2002 21:28:46 -0000
***************
*** 48,67 ****
#include "adaint.h"
! #ifdef __EMX__
! int max_path_len = _MAX_PATH;
! #elif defined (VMS)
#include <unixlib.h>
! int max_path_len = 4096; /* PATH_MAX */
!
! #elif defined (__vxworks) || defined (__OPENNT)
!
! int max_path_len = PATH_MAX;
!
! #else
#ifdef linux
-
/* Don't use macros on GNU/Linux since they cause incompatible changes between
glibc 2.0 and 2.1 */
--- 48,58 ----
#include "adaint.h"
! #ifdef VMS
#include <unixlib.h>
! #endif
#ifdef linux
/* Don't use macros on GNU/Linux since they cause incompatible changes between
glibc 2.0 and 2.1 */
***************
*** 74,85 ****
#ifdef stdout
# undef stdout
#endif
-
- #endif
-
- #include <sys/param.h>
-
- int max_path_len = MAXPATHLEN;
#endif
/* The _IONBF value in CYGNUS or MINGW32 stdio.h is wrong. */
--- 65,70 ----
***************
*** 185,191 ****
strcpy (buffer, nam);
else
{
! _fullpath (buffer, nam, max_path_len);
for (p = buffer; *p; p++)
if (*p == '/')
--- 170,176 ----
strcpy (buffer, nam);
else
{
! _fullpath (buffer, nam, __gnat_max_path_len);
for (p = buffer; *p; p++)
if (*p == '/')
***************
*** 210,219 ****
strcpy (buffer, __gnat_to_host_file_spec (buffer));
else
{
! char *nambuffer = alloca (max_path_len);
strcpy (nambuffer, buffer);
! strcpy (buffer, getcwd (buffer, max_path_len, 0));
strcat (buffer, "/");
strcat (buffer, nambuffer);
strcpy (buffer, __gnat_to_host_file_spec (buffer));
--- 195,204 ----
strcpy (buffer, __gnat_to_host_file_spec (buffer));
else
{
! char *nambuffer = alloca (__gnat_max_path_len);
strcpy (nambuffer, buffer);
! strcpy (buffer, getcwd (buffer, __gnat_max_path_len, 0));
strcat (buffer, "/");
strcat (buffer, nambuffer);
strcpy (buffer, __gnat_to_host_file_spec (buffer));
***************
*** 224,230 ****
#else
if (nam[0] != '/')
{
! p = getcwd (buffer, max_path_len);
if (p == 0)
{
buffer[0] = '\0';
--- 209,215 ----
#else
if (nam[0] != '/')
{
! p = getcwd (buffer, __gnat_max_path_len);
if (p == 0)
{
buffer[0] = '\0';
Index: g-dirope.adb
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/g-dirope.adb,v
retrieving revision 1.8
diff -c -r1.8 g-dirope.adb
*** g-dirope.adb 14 Mar 2002 10:59:18 -0000 1.8
--- g-dirope.adb 19 May 2002 21:28:47 -0000
***************
*** 502,508 ****
---------------------
Max_Path : Integer;
! pragma Import (C, Max_Path, "max_path_len");
function Get_Current_Dir return Dir_Name_Str is
Current_Dir : String (1 .. Max_Path + 1);
--- 502,508 ----
---------------------
Max_Path : Integer;
! pragma Import (C, Max_Path, "__gnat_max_path_len");
function Get_Current_Dir return Dir_Name_Str is
Current_Dir : String (1 .. Max_Path + 1);
Index: g-os_lib.adb
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/g-os_lib.adb,v
retrieving revision 1.5
diff -c -r1.5 g-os_lib.adb
*** g-os_lib.adb 14 Mar 2002 10:59:21 -0000 1.5
--- g-os_lib.adb 19 May 2002 21:28:47 -0000
***************
*** 877,883 ****
return String
is
Max_Path : Integer;
! pragma Import (C, Max_Path, "max_path_len");
-- Maximum length of a path name
procedure Get_Current_Dir
--- 877,883 ----
return String
is
Max_Path : Integer;
! pragma Import (C, Max_Path, "__gnat_max_path_len");
-- Maximum length of a path name
procedure Get_Current_Dir
Index: i-cstrea.ads
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/i-cstrea.ads,v
retrieving revision 1.3
diff -c -r1.3 i-cstrea.ads
*** i-cstrea.ads 14 Mar 2002 10:59:28 -0000 1.3
--- i-cstrea.ads 19 May 2002 21:28:48 -0000
***************
*** 283,289 ****
pragma Import (C, set_binary_mode, "__gnat_set_binary_mode");
pragma Import (C, set_text_mode, "__gnat_set_text_mode");
! pragma Import (C, max_path_len, "max_path_len");
pragma Import (C, full_name, "__gnat_full_name");
-- The following may be implemented as macros, and so are supported
--- 283,289 ----
pragma Import (C, set_binary_mode, "__gnat_set_binary_mode");
pragma Import (C, set_text_mode, "__gnat_set_text_mode");
! pragma Import (C, max_path_len, "__gnat_max_path_len");
pragma Import (C, full_name, "__gnat_full_name");
-- The following may be implemented as macros, and so are supported
Index: osint.adb
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/osint.adb,v
retrieving revision 1.8
diff -c -r1.8 osint.adb
*** osint.adb 14 Mar 2002 10:59:34 -0000 1.8
--- osint.adb 19 May 2002 21:28:49 -0000
***************
*** 941,947 ****
pragma Import (C, Get_Current_Dir, "__gnat_get_current_dir");
Max_Path : Integer;
! pragma Import (C, Max_Path, "max_path_len");
-- Maximum length of a path name
Current_Dir : String_Ptr;
--- 941,947 ----
pragma Import (C, Get_Current_Dir, "__gnat_get_current_dir");
Max_Path : Integer;
! pragma Import (C, Max_Path, "__gnat_max_path_len");
-- Maximum length of a path name
Current_Dir : String_Ptr;
Index: xr_tabls.adb
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ada/xr_tabls.adb,v
retrieving revision 1.3
diff -c -r1.3 xr_tabls.adb
*** xr_tabls.adb 14 Mar 2002 11:00:22 -0000 1.3
--- xr_tabls.adb 19 May 2002 21:28:49 -0000
***************
*** 629,635 ****
else
declare
Max_Path : Integer;
! pragma Import (C, Max_Path, "max_path_len");
Base2 : Dir_Name_Str (1 .. Max_Path);
Last : Natural;
--- 629,635 ----
else
declare
Max_Path : Integer;
! pragma Import (C, Max_Path, "__gnat_max_path_len");
Base2 : Dir_Name_Str (1 .. Max_Path);
Last : Natural;