Check return value from xgetcwd

* src/misc.c (chdir_arg,tar_getcdpath): Check for non-NULL
return from xgetcwd. The function returns NULL for any
error originating from getcwd.
This commit is contained in:
Sergey Poznyakoff
2019-03-03 09:02:20 +02:00
parent 44cfdfb8b6
commit 66162927eb

View File

@@ -314,8 +314,6 @@ normalize_filename (int cdidx, const char *name)
size_t copylen; size_t copylen;
bool need_separator; bool need_separator;
if (!cdpath)
call_arg_fatal ("getcwd", ".");
copylen = strlen (cdpath); copylen = strlen (cdpath);
need_separator = ! (DOUBLE_SLASH_IS_DISTINCT_ROOT need_separator = ! (DOUBLE_SLASH_IS_DISTINCT_ROOT
&& copylen == 2 && ISSLASH (cdpath[1])); && copylen == 2 && ISSLASH (cdpath[1]));
@@ -922,6 +920,8 @@ chdir_arg (char const *dir)
{ {
wd[wd_count].name = "."; wd[wd_count].name = ".";
wd[wd_count].abspath = xgetcwd (); wd[wd_count].abspath = xgetcwd ();
if (!wd[wd_count].abspath)
call_arg_fatal ("getcwd", ".");
wd[wd_count].fd = AT_FDCWD; wd[wd_count].fd = AT_FDCWD;
wd_count++; wd_count++;
} }
@@ -1047,7 +1047,11 @@ tar_getcdpath (int idx)
{ {
static char *cwd; static char *cwd;
if (!cwd) if (!cwd)
cwd = xgetcwd (); {
cwd = xgetcwd ();
if (!cwd)
call_arg_fatal ("getcwd", ".");
}
return cwd; return cwd;
} }
return wd[idx].abspath; return wd[idx].abspath;