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

427804
From e890d08e16ea0621966a7ae35cce53ccb44a472e Mon Sep 17 00:00:00 2001
427804
From: seetharaman-rajagopal <seetharaman.chn@gmail.com>
427804
Date: Mon, 13 Feb 2023 08:14:04 +0000
427804
Subject: [PATCH] CVE-2022-37704 - privilege escaltion form amandabackup user
427804
 to root -fix
427804
427804
---
427804
 client-src/rundump.c | 135 +++++++++++++++++++++++++++++++++++++++++++
427804
 1 file changed, 135 insertions(+)
427804
427804
diff --git a/client-src/rundump.c b/client-src/rundump.c
427804
index 0b354d70bf..bba5699847 100644
427804
--- a/client-src/rundump.c
427804
+++ b/client-src/rundump.c
427804
@@ -40,6 +40,8 @@
427804
 #include "conffile.h"
427804
 
427804
 int main(int argc, char **argv);
427804
+static void validate_dump_option(int argc, char ** argv);
427804
+static void validate_xfsdump_options(int argc, char ** argv);
427804
 
427804
 #if defined(VDUMP) || defined(XFSDUMP)
427804
 #  undef USE_RUNDUMP
427804
@@ -160,14 +162,17 @@ main(
427804
 
427804
 #if defined(DUMP)
427804
         dump_program = DUMP;
427804
+        validate_dump_option(argc, argv);
427804
 #else
427804
 # if defined(XFSDUMP)
427804
         dump_program = XFSDUMP;
427804
+        validate_xfsdump_options(argc, argv);
427804
 # else
427804
 #  if defined(VXDUMP)
427804
 	dump_program = VXDUMP;
427804
 #  else
427804
         dump_program = "dump";
427804
+        validate_dump_option(argc, argv);
427804
 #  endif
427804
 # endif
427804
 #endif
427804
@@ -203,3 +208,133 @@ main(
427804
     return 1;
427804
 #endif								/* } */
427804
 }
427804
+
427804
+void validate_dump_option(int argc, char ** argv)
427804
+{
427804
+	int c;
427804
+	int numargs = argc;
427804
+	while (numargs > 0)
427804
+	{
427804
+		c = getopt(argc, argv, "0123456789ab:cd:e:f:h:j:kmnqs:uvwyz:A:B:D:I:L:MQ:ST:W");
427804
+		switch (c) {
427804
+			case -1:
427804
+				optind++;
427804
+			break;
427804
+			case '?':
427804
+				//option is not valid
427804
+				error("error [%s invalid option: %s]\n", get_pname(), argv[optind-1]);
427804
+			break;
427804
+			// All this options takes another argument
427804
+			case 'b':
427804
+			case 'd':
427804
+			case 'e':
427804
+			case 'f':
427804
+			case 'h':
427804
+			case 'j':
427804
+			case 's':
427804
+			case 'z':
427804
+			case 'A':
427804
+			case 'B':
427804
+			case 'D':
427804
+			case 'I':
427804
+			case 'L':
427804
+			case 'Q':
427804
+			case 'T':
427804
+			{
427804
+				// get optarg and check it against NULL. If it is null, then return error.
427804
+				if (optarg == NULL) {
427804
+					error ("error [%s additional parameter is missing for option: %c]\n", get_pname(), c);
427804
+				}
427804
+				break;
427804
+			}
427804
+			case '0':
427804
+			case '1':
427804
+			case '2':
427804
+			case '3':
427804
+			case '4':
427804
+			case '5':
427804
+			case '6':
427804
+			case '7':
427804
+			case '8':
427804
+			case '9':
427804
+			case 'a':
427804
+			case 'c':
427804
+			case 'k':
427804
+			case 'm':
427804
+			case 'n':
427804
+			case 'q':
427804
+			case 'u':
427804
+			case 'v':
427804
+			case 'w':
427804
+			case 'y':
427804
+			case 'M':
427804
+			case 'S':
427804
+			case 'W':
427804
+			{
427804
+				break;
427804
+			}
427804
+			default:
427804
+				error ("error [%s invalid option: %c]\n", get_pname(), c);
427804
+			break;
427804
+		}
427804
+		numargs--;
427804
+	}
427804
+}
427804
+
427804
+void validate_xfsdump_options(int argc, char ** argv)
427804
+{
427804
+	int c;
427804
+	int numargs = argc;
427804
+	while (numargs > 0)
427804
+	{
427804
+		c = getopt(argc, argv, "ab:d:ef:l:mop:qs:t:v:z:AB:DFI:JL:M:RT");
427804
+		switch (c) {
427804
+			case -1:
427804
+				optind++;
427804
+			break;
427804
+			case '?':
427804
+				//option is not valid
427804
+				error ("error [%s invalid option: %s]\n", get_pname(), argv[optind-1]);
427804
+			break;
427804
+			// All this options takes another argument
427804
+			case 'b':
427804
+			case 'd':
427804
+			case 'f':
427804
+			case 'l':
427804
+			case 'p':
427804
+			case 's':
427804
+			case 't':
427804
+			case 'v':
427804
+			case 'z':
427804
+			case 'B':
427804
+			case 'I':
427804
+			case 'L':
427804
+			case 'M':
427804
+			{
427804
+				// get optarg and check it against NULL. If it is null, then return error.
427804
+				if (optarg == NULL) {
427804
+					error ("error [%s additional parameter is missing for option: %c]\n", get_pname(), c);
427804
+				}
427804
+				break;
427804
+			}
427804
+			case 'a':
427804
+			case 'e':
427804
+			case 'm':
427804
+			case 'o':
427804
+			case 'q':
427804
+			case 'A':
427804
+			case 'D':
427804
+			case 'F':
427804
+			case 'J':
427804
+			case 'R':
427804
+			case 'T':
427804
+			{
427804
+				break;
427804
+			}
427804
+			default:
427804
+				error ("error [%s invalid option: %c]\n", get_pname(), c);
427804
+			break;
427804
+		}
427804
+		numargs--;
427804
+	}
427804
+}