Blame SOURCES/tar-1.30-xgetcwd-null-return-check.patch

7893ae
From 60acf5a7407ef263aaf7d3751da08167b1990eb0 Mon Sep 17 00:00:00 2001
7893ae
From: Sergey Poznyakoff <gray@gnu.org>
7893ae
Date: Wed, 20 May 2020 13:35:28 +0200
7893ae
Subject: [PATCH] Check return value from xgetcwd
7893ae
7893ae
* src/misc.c (chdir_arg,tar_getcdpath): Check for non-NULL
7893ae
return from xgetcwd. The function returns NULL for any
7893ae
error originating from getcwd.
7893ae
---
7893ae
 src/misc.c | 10 +++++++---
7893ae
 1 file changed, 7 insertions(+), 3 deletions(-)
7893ae
7893ae
diff --git a/src/misc.c b/src/misc.c
7893ae
index cd07f53..eccf6f9 100644
7893ae
--- a/src/misc.c
7893ae
+++ b/src/misc.c
7893ae
@@ -301,8 +301,6 @@ normalize_filename (int cdidx, const char *name)
7893ae
       size_t copylen;
7893ae
       bool need_separator;
7893ae
 
7893ae
-      if (!cdpath)
7893ae
-	call_arg_fatal ("getcwd", ".");
7893ae
       copylen = strlen (cdpath);
7893ae
       need_separator = ! (DOUBLE_SLASH_IS_DISTINCT_ROOT
7893ae
 			  && copylen == 2 && ISSLASH (cdpath[1]));
7893ae
@@ -909,6 +907,8 @@ chdir_arg (char const *dir)
7893ae
 	{
7893ae
 	  wd[wd_count].name = ".";
7893ae
 	  wd[wd_count].abspath = xgetcwd ();
7893ae
+    if (!wd[wd_count].abspath)
7893ae
+	    call_arg_fatal ("getcwd", ".");
7893ae
 	  wd[wd_count].fd = AT_FDCWD;
7893ae
 	  wd_count++;
7893ae
 	}
7893ae
@@ -1034,7 +1034,11 @@ tar_getcdpath (int idx)
7893ae
     {
7893ae
       static char *cwd;
7893ae
       if (!cwd)
7893ae
-	cwd = xgetcwd ();
7893ae
+	      {
7893ae
+          cwd = xgetcwd ();
7893ae
+          if (!cwd)
7893ae
+            call_arg_fatal ("getcwd", ".");
7893ae
+	      }
7893ae
       return cwd;
7893ae
     }
7893ae
   return wd[idx].abspath;
7893ae
-- 
7893ae
2.24.1
7893ae