f4af7d
diff --git a/lib/rmt.h b/lib/rmt.h
f4af7d
index 2ce9dc5..4580e49 100644
f4af7d
--- a/lib/rmt.h
f4af7d
+++ b/lib/rmt.h
f4af7d
@@ -17,8 +17,9 @@
f4af7d
    along with this program; if not, write to the Free Software Foundation,
f4af7d
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
f4af7d
 
f4af7d
-extern char *rmt_command;
f4af7d
-extern char *rmt_dev_name__;
f4af7d
+/* upstream fix 0b3d84a0ee */
f4af7d
+extern char const *rmt_command;
f4af7d
+extern char const *rmt_dev_name__;
f4af7d
 
f4af7d
 int rmt_open__ (const char *, int, int, const char *);
f4af7d
 int rmt_close__ (int);
f4af7d
diff --git a/lib/rtapelib.c b/lib/rtapelib.c
f4af7d
index 3aee428..1cef0fc 100644
f4af7d
--- a/lib/rtapelib.c
f4af7d
+++ b/lib/rtapelib.c
f4af7d
@@ -90,10 +90,10 @@ static int from_remote[MAXUNIT][2] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
f4af7d
 /* The pipes for sending data to remote tape drives.  */
f4af7d
 static int to_remote[MAXUNIT][2] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}};
f4af7d
 
f4af7d
-char *rmt_command = DEFAULT_RMT_COMMAND;
f4af7d
+char const *rmt_command = DEFAULT_RMT_COMMAND; /* upstream fix 0b3d84a0ee */
f4af7d
 
f4af7d
 /* Temporary variable used by macros in rmt.h.  */
f4af7d
-char *rmt_dev_name__;
f4af7d
+char const *rmt_dev_name__; /* upstream fix 0b3d84a0ee */
f4af7d
 
f4af7d
 /* If true, always consider file names to be local, even if they contain
f4af7d
    colons */
f4af7d
@@ -490,15 +490,17 @@ rmt_open__ (const char *file_name, int open_mode, int bias,
f4af7d
       {
f4af7d
 	/* Child.  */
f4af7d
 
f4af7d
-	close (STDIN_FILENO);
f4af7d
-	dup (to_remote[remote_pipe_number][PREAD]);
f4af7d
-	close (to_remote[remote_pipe_number][PREAD]);
f4af7d
-	close (to_remote[remote_pipe_number][PWRITE]);
f4af7d
-
f4af7d
-	close (STDOUT_FILENO);
f4af7d
-	dup (from_remote[remote_pipe_number][PWRITE]);
f4af7d
-	close (from_remote[remote_pipe_number][PREAD]);
f4af7d
-	close (from_remote[remote_pipe_number][PWRITE]);
f4af7d
+	/* upstream fix 0b3d84a0ee */
f4af7d
+	if (dup2 (to_remote[remote_pipe_number][PREAD], STDIN_FILENO) < 0
f4af7d
+	    || (to_remote[remote_pipe_number][PREAD] != STDIN_FILENO
f4af7d
+		&& close (to_remote[remote_pipe_number][PREAD]) != 0)
f4af7d
+	    || (to_remote[remote_pipe_number][PWRITE] != STDIN_FILENO
f4af7d
+		&& close (to_remote[remote_pipe_number][PWRITE]) != 0)
f4af7d
+	    || dup2 (from_remote[remote_pipe_number][PWRITE], STDOUT_FILENO) < 0
f4af7d
+	    || close (from_remote[remote_pipe_number][PREAD]) != 0
f4af7d
+	    || close (from_remote[remote_pipe_number][PWRITE]) != 0)
f4af7d
+	  error (EXIT_ON_EXEC_ERROR, errno,
f4af7d
+		 _("Cannot redirect files for remote shell"));
f4af7d
 
f4af7d
 	sys_reset_uid_gid ();
f4af7d
 
f4af7d
diff --git a/lib/system.h b/lib/system.h
f4af7d
index 2deb585..599d4ba 100644
f4af7d
--- a/lib/system.h
f4af7d
+++ b/lib/system.h
f4af7d
@@ -471,8 +471,13 @@ char *getenv ();
f4af7d
 # define SET_BINARY_MODE(arc)
f4af7d
 # define ERRNO_IS_EACCES 0
f4af7d
 # define TTY_NAME "/dev/tty"
f4af7d
-# define sys_reset_uid_gid() \
f4af7d
- do { setuid (getuid ()); setgid (getgid ()); } while (0)
f4af7d
+
f4af7d
+/* upstream fix 0b3d84a0ee */
f4af7d
+# define sys_reset_uid_gid()					\
f4af7d
+  do {								\
f4af7d
+    if (! (setuid (getuid ()) == 0 && setgid (getgid ()) == 0)) \
f4af7d
+      abort ();							\
f4af7d
+  } while (0)
f4af7d
 #endif
f4af7d
 
f4af7d
 #if XENIX
f4af7d
diff --git a/src/compare.c b/src/compare.c
f4af7d
index 273269a..796d7aa 100644
f4af7d
--- a/src/compare.c
f4af7d
+++ b/src/compare.c
f4af7d
@@ -362,7 +362,7 @@ static void
f4af7d
 diff_dumpdir (void)
f4af7d
 {
f4af7d
   const char *dumpdir_buffer;
f4af7d
-  dev_t dev = 0;
f4af7d
+  /* upstream fix 5bb04335079 */
f4af7d
   struct stat stat_data;
f4af7d
 
f4af7d
   if (deref_stat (current_stat_info.file_name, &stat_data) != 0)
f4af7d
@@ -372,8 +372,7 @@ diff_dumpdir (void)
f4af7d
       else
f4af7d
 	stat_error (current_stat_info.file_name);
f4af7d
     }
f4af7d
-  else
f4af7d
-    dev = stat_data.st_dev;
f4af7d
+  /* upstream fix 5bb04335079 */
f4af7d
 
f4af7d
   dumpdir_buffer = directory_contents (scan_directory (&current_stat_info));
f4af7d
 
f4af7d
diff --git a/tests/genfile.c b/tests/genfile.c
f4af7d
index 8541be6..fa480ef 100644
f4af7d
--- a/tests/genfile.c
f4af7d
+++ b/tests/genfile.c
f4af7d
@@ -485,9 +485,11 @@ generate_files_from_list ()
f4af7d
 static void
f4af7d
 mkhole (int fd, off_t displ)
f4af7d
 {
f4af7d
-  if (lseek (fd, displ, SEEK_CUR) == -1)
f4af7d
+  off_t offset = lseek (fd, displ, SEEK_CUR);
f4af7d
+  if (offset < 0)
f4af7d
     error (EXIT_FAILURE, errno, "lseek");
f4af7d
-  ftruncate (fd, lseek (fd, 0, SEEK_CUR));
f4af7d
+  if (ftruncate (fd, offset) != 0)
f4af7d
+    error (EXIT_FAILURE, errno, "ftruncate");
f4af7d
 }
f4af7d
 
f4af7d
 static void
f4af7d
@@ -685,13 +687,18 @@ exec_checkpoint (struct action *p)
f4af7d
 	    error (0, errno, _("cannot open `%s'"), p->name);
f4af7d
 	    break;
f4af7d
 	  }
f4af7d
-	ftruncate (fd, p->size);
f4af7d
+	if (ftruncate (fd, p->size) != 0)
f4af7d
+	  {
f4af7d
+	    error (0, errno, _("cannot truncate `%s'"), p->name);
f4af7d
+	    break;
f4af7d
+	  }
f4af7d
 	close (fd);
f4af7d
       }
f4af7d
       break;
f4af7d
 
f4af7d
     case OPT_EXEC:
f4af7d
-      system (p->name);
f4af7d
+      if (system (p->name) != 0)
f4af7d
+	error (0, 0, _("command failed: %s"), p->name);
f4af7d
       break;
f4af7d
 
f4af7d
     case OPT_UNLINK:
f4af7d
@@ -761,7 +768,8 @@ exec_command (void)
f4af7d
   signal (SIGCHLD, SIG_DFL);
f4af7d
 #endif
f4af7d
 
f4af7d
-  pipe (fd);
f4af7d
+  if (pipe (fd) != 0)
f4af7d
+    error (EXIT_FAILURE, errno, "pipe");
f4af7d
 
f4af7d
   pid = fork ();
f4af7d
   if (pid == -1)