From: Joel Rosdahl Date: Wed, 3 Aug 2011 18:10:57 +0000 (+0200) Subject: Don't crash when getcwd() fails X-Git-Tag: v3.1.6~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83f5a1e3b4a20c7a2a2d8bce907958ac3f3d9662;p=thirdparty%2Fccache.git Don't crash when getcwd() fails --- diff --git a/ccache.c b/ccache.c index 0f4b4c761..3bb6d77c3 100644 --- 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 d68d8c558..1be5f0811 100644 --- 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;