Blame SOURCES/amanda-3.5.2-CVE-2022-37704-fixup.patch

ff65fb
diff --git a/client-src/rundump.c b/client-src/rundump.c
ff65fb
index bba569984..85962d11c 100644
ff65fb
--- a/client-src/rundump.c
ff65fb
+++ b/client-src/rundump.c
ff65fb
@@ -43,6 +43,16 @@ int main(int argc, char **argv);
ff65fb
 static void validate_dump_option(int argc, char ** argv);
ff65fb
 static void validate_xfsdump_options(int argc, char ** argv);
ff65fb
 
ff65fb
+/*
ff65fb
+ * Has USE_RUNDUMP been explicitly requsted?
ff65fb
+ * If not, we will not use rundump for DUMP,
ff65fb
+ * although we sill may need to use it for
ff65fb
+ * VDUMP or XFSDUMP
ff65fb
+ */
ff65fb
+#if defined(USE_RUNDUMP)
ff65fb
+#  define USE_RUNDUMP_FOR_DUMP
ff65fb
+#endif
ff65fb
+
ff65fb
 #if defined(VDUMP) || defined(XFSDUMP)
ff65fb
 #  undef USE_RUNDUMP
ff65fb
 #  define USE_RUNDUMP
ff65fb
@@ -138,9 +148,10 @@ main(
ff65fb
 
ff65fb
 #ifdef XFSDUMP
ff65fb
 
ff65fb
-    if (g_str_equal(argv[0], "xfsdump"))
ff65fb
+    if (g_str_equal(argv[0], "xfsdump")) {
ff65fb
         dump_program = XFSDUMP;
ff65fb
-    else /* strcmp(argv[0], "xfsdump") != 0 */
ff65fb
+        validate_xfsdump_options(argc, argv);
ff65fb
+    } else /* strcmp(argv[0], "xfsdump") != 0 */
ff65fb
 
ff65fb
 #endif
ff65fb
 
ff65fb
@@ -160,9 +171,14 @@ main(
ff65fb
 
ff65fb
 #endif
ff65fb
 
ff65fb
+      {
ff65fb
 #if defined(DUMP)
ff65fb
+# if defined(USE_RUNDUMP_FOR_DUMP)
ff65fb
         dump_program = DUMP;
ff65fb
         validate_dump_option(argc, argv);
ff65fb
+# else
ff65fb
+        error("error [%s not running %s : run it directly]\n", get_pname(), DUMP);
ff65fb
+# endif
ff65fb
 #else
ff65fb
 # if defined(XFSDUMP)
ff65fb
         dump_program = XFSDUMP;
ff65fb
@@ -176,6 +192,7 @@ main(
ff65fb
 #  endif
ff65fb
 # endif
ff65fb
 #endif
ff65fb
+      }
ff65fb
 
ff65fb
 
ff65fb
     /*
ff65fb
@@ -197,6 +214,24 @@ main(
ff65fb
     amfree(cmdline);
ff65fb
 
ff65fb
     env = safe_env();
ff65fb
+    //Filter or Discard RSH Environmental variable
ff65fb
+    int env_count = 0;
ff65fb
+    for (int i = 0; env[i] != NULL; i++){
ff65fb
+        env_count++;
ff65fb
+    }
ff65fb
+    for (int i = 0; i < env_count; i++){
ff65fb
+        if (strncmp(env[i], "RSH=", 4) == 0){
ff65fb
+            // Remove RSH
ff65fb
+            g_free(env[i]);
ff65fb
+            // move array elements one step left - which are after "RSH"
ff65fb
+            for (int j = i; j < env_count; j++){
ff65fb
+                env[j] = env[j + 1];
ff65fb
+            }
ff65fb
+            //decrease the variable count
ff65fb
+            env[env_count-1] = NULL;
ff65fb
+            break;
ff65fb
+        }
ff65fb
+    }
ff65fb
     execve(dump_program, argv, env);
ff65fb
     free_env(env);
ff65fb
 
ff65fb
diff --git a/client-src/runtar.c b/client-src/runtar.c
ff65fb
index 499c7dfec..880068bc4 100644
ff65fb
--- a/client-src/runtar.c
ff65fb
+++ b/client-src/runtar.c
ff65fb
@@ -191,9 +191,13 @@ main(
ff65fb
 		g_str_has_prefix(argv[i],"--newer") ||
ff65fb
 		g_str_has_prefix(argv[i],"--exclude-from") ||
ff65fb
 		g_str_has_prefix(argv[i],"--files-from")) {
ff65fb
-		good_option++;
ff65fb
+		if (strchr(argv[i], '=')) {
ff65fb
+		    good_option++;
ff65fb
+		} else {
ff65fb
+		    /* Accept theses options with the following argument */
ff65fb
+		    good_option += 2;
ff65fb
+		}
ff65fb
 	    } else if (argv[i][0] != '-') {
ff65fb
-		/* argument values are accounted for here */
ff65fb
 		good_option++;
ff65fb
 	    }
ff65fb
 	}