Properly handle return from getcwd.
authorNelson Ferreira <nelson.ferreira@ieee.org>
Sun, 6 Dec 2015 21:05:30 +0000 (16:05 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Sun, 6 Dec 2015 21:05:30 +0000 (16:05 -0500)
* src/realpath.c (xrealpath): Is getcwd returns NULL, also return
NULL.  If we can't determine the cwd, then any relative path
processing fails.

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
src/realpath.c

index 1ccfd70..a8c7a3c 100644 (file)
@@ -80,10 +80,14 @@ char *xrealpath(const char *path, char *restrict resolved_path)
 
        /* If it's a relative pathname use getcwd for starters. */
        if (abslen == 0) {
-               getcwd(new_path, PATH_MAX - 1);
-               new_path += strlen(new_path);
-               if (!IS_DIRECTORY_SEP(new_path[-1]))
-                       *new_path++ = DIRECTORY_SEP;
+               void *ok = getcwd(new_path, PATH_MAX - 1);
+               if (ok) {
+                       new_path += strlen(new_path);
+                       if (!IS_DIRECTORY_SEP(new_path[-1]))
+                               *new_path++ = DIRECTORY_SEP;
+               } else {
+                       return NULL;
+               }
        } else {
                /* Copy first directory sep. */
                strncpy(new_path, path, abslen);