]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't crash when getcwd() fails
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 3 Aug 2011 18:10:57 +0000 (20:10 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 3 Aug 2011 18:10:57 +0000 (20:10 +0200)
ccache.c
util.c

index 0f4b4c761abb1954373331392cb604263e6bf37b..3bb6d77c3829ca99e0cdfcfc51a5df265d343ca6 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -2114,6 +2114,10 @@ ccache_main(int argc, char *argv[])
        }
 
        current_working_dir = get_cwd();
+       if (!current_working_dir) {
+               cc_log("Could not determine current working directory");
+               failed();
+       }
        cache_dir = getenv("CCACHE_DIR");
        if (cache_dir) {
                cache_dir = x_strdup(cache_dir);
diff --git a/util.c b/util.c
index d68d8c558a964c077f23ab4fe3ba330d11dd7670..1be5f0811af01450b845e61c304a73d5af336f6c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -867,7 +867,8 @@ gnu_getcwd(void)
                }
                free(buffer);
                if (errno != ERANGE) {
-                       return 0;
+                       cc_log("getcwd error: %d (%s)", errno, strerror(errno));
+                       return NULL;
                }
                size *= 2;
        }
@@ -921,6 +922,9 @@ get_cwd(void)
        struct stat st_cwd;
 
        cwd = gnu_getcwd();
+       if (!cwd) {
+               return NULL;
+       }
        pwd = getenv("PWD");
        if (!pwd) {
                return cwd;