Patchwork [libfortran] PR 51803 getcwd() failure

login
register
mail settings
Submitter Janne Blomqvist
Date Jan. 12, 2012, 10:01 a.m.
Message ID <CAO9iq9GwLscA+H0s5OnqUxGhD4N480thnzq8OWDv6LGO+r3Dsg@mail.gmail.com>
Download mbox | patch
Permalink /patch/135606/
State New
Headers show

Comments

Janne Blomqvist - Jan. 12, 2012, 10:01 a.m.
On Wed, Jan 11, 2012 at 14:55, Tobias Burnus <burnus@net-b.de> wrote:
> Dear all,
>
> this is a follow up patch, which I think provides a better handling if
> either getcwd fails or is not availble - or if the pathname in argv[0]
> already is an absolute patch, in which case concatenating
> current-working-directory + '/' + argv[0] does not really make sense.
>
> Build on x86-64-linux.
> OK for the trunk?

Committed the patch below, which implements Tobias' suggestion, as obvious.

Patch

Index: runtime/main.c
===================================================================
--- runtime/main.c      (revision 183121)
+++ runtime/main.c      (working copy)
@@ -124,12 +124,17 @@  store_exe_path (const char * argv0)

 #ifdef HAVE_GETCWD
   cwd = getcwd (buf, sizeof (buf));
-  if (!cwd)
-    cwd = ".";
 #else
-  cwd = ".";
+  cwd = NULL;
 #endif

+  if (!cwd)
+    {
+      exe_path = argv0;
+      please_free_exe_path_when_done = 0;
+      return;
+    }
+
   /* exe_path will be cwd + "/" + argv[0] + "\0".  This will not work
      if the executable is not in the cwd, but at this point we're out
      of better ideas.  */
Index: ChangeLog
===================================================================
--- ChangeLog   (revision 183121)
+++ ChangeLog   (working copy)
@@ -1,3 +1,10 @@ 
+2012-01-12  Janne Blomqvist  <jb@gcc.gnu.org>
+           Tobias Burnus  <burnus@net-b.de>
+
+       PR libfortran/51803
+       * runtime/main.c (store_exe_path): Avoid malloc if getcwd fails or
+       is not available.
+
 2012-01-11  Tobias Burnus  <burnus@net-b.de>

        * runtime/main.c (store_exe_path): Fix absolute path
@@ -5,6 +12,7 @@ 

 2012-01-11  Janne Blomqvist  <jb@gcc.gnu.org>
            Mike Stump  <mikestump@comcast.net>
+
        PR libfortran/51803
        * runtime/main.c (store_exe_path): Handle getcwd failure and lack
        of the function better.