[Rd] [PATCH] R ignores PATH_MAX and fails in long directories (PR#14228)

From: <mstokely_at_google.com>
Date: Sat, 06 Mar 2010 00:10:12 +0100 (CET)


Full_Name: Murray Stokely
Version: 2.10.1
OS: Linux
Submission from: (NULL) (216.239.45.4)

The Defn.h header includes limits.h for PATH_MAX and then checks if it hasn't been defined and if not sets something manually. Some of the R code uses PATH_MAX but a lot of other functions in unix/sys-unix.c and main/startup.c just hardcodes a limit of 256 characters.

In my environment this is not always enough, so I ran into this being a problem, and verified that the attached fix resolves the problem with R 2.10.1.

To duplicate the problem:

  1. Create a large directory: echo `seq 80` | tr ' ' '_' | sed -e 's|\(.*\)|/tmp/\1/\1/\1|g' | xargs mkdir -p
  2. Copy R into it
  3. Launch R from that directory / with that R_HOME You don't be able to load the base module or run other functions.

I have prepared 2 patches, one against the trunk in Subversion : http://people.FreeBSD.org/~murray/maxpath-svn-trunk.patch

And one against the 2.10 release branch :

http://people.FreeBSD.org/~murray/maxpath-svn-2-10-branch.patch

Trunk patch pasted below :

Index: src/unix/sys-unix.c


     fp = NULL;
@@ -72,7 +72,7 @@

            return fp;
        if((home = getenv("HOME")) == NULL)
            return NULL;
-       sprintf(buf, "%s/.Rprofile", home);
+       snprintf(buf, PATH_MAX, "%s/.Rprofile", home);
        if((fp = R_fopen(buf, "r")))
            return fp;
     }

Index: src/main/startup.c

     fp = NULL;
@@ -90,10 +90,10 @@

        if ((fp = R_fopen(getenv("R_PROFILE"), "r"))) return fp;
        if ((fp = R_fopen(getenv("RPROFILE"), "r"))) return fp;
 #ifdef R_ARCH
-       snprintf(buf, 256, "%s/etc/%s/Rprofile.site", R_Home, R_ARCH);
+       snprintf(buf, PATH_MAX, "%s/etc/%s/Rprofile.site", R_Home, R_ARCH);
        if ((fp = R_fopen(buf, "r"))) return fp;
 #endif
-       snprintf(buf, 256, "%s/etc/Rprofile.site", R_Home);
+       snprintf(buf, PATH_MAX, "%s/etc/Rprofile.site", R_Home);
        if ((fp = R_fopen(buf, "r"))) return fp;
     }
     return fp;

Index: src/main/main.c
     if (strcmp(R_GUIType, "Tk") == 0) {
-       char buf[256];
+       char buf[PATH_MAX];

-       snprintf(buf, 256, "%s/library/tcltk/exec/Tk-frontend.R", R_Home);
+       snprintf(buf, PATH_MAX, "%s/library/tcltk/exec/Tk-frontend.R", R_Home);
        R_LoadProfile(R_fopen(buf, "r"), R_GlobalEnv);
     }

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 08 Mar 2010 - 09:01:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 11 Mar 2010 - 14:01:00 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive