Blame SOURCES/dhcp-4.2.5-options_overflow.patch

45d60a
diff --git a/common/options.c b/common/options.c
45d60a
index 83e0384..8a1deca 100644
45d60a
--- a/common/options.c
45d60a
+++ b/common/options.c
45d60a
@@ -1672,7 +1672,8 @@ format_min_length(format, oc)
45d60a
 
45d60a
 
45d60a
 /* Format the specified option so that a human can easily read it. */
45d60a
-
45d60a
+/* Maximum pretty printed size */
45d60a
+#define MAX_OUTPUT_SIZE 32*1024
45d60a
 const char *pretty_print_option (option, data, len, emit_commas, emit_quotes)
45d60a
 	struct option *option;
45d60a
 	const unsigned char *data;
45d60a
@@ -1680,8 +1681,9 @@ const char *pretty_print_option (option, data, len, emit_commas, emit_quotes)
45d60a
 	int emit_commas;
45d60a
 	int emit_quotes;
45d60a
 {
45d60a
-	static char optbuf [32768]; /* XXX */
45d60a
-	static char *endbuf = &optbuf[sizeof(optbuf)];
45d60a
+	/* We add 128 byte pad so we don't have to add checks everywhere. */
45d60a
+	static char optbuf [MAX_OUTPUT_SIZE + 128]; /* XXX */
45d60a
+	static char *endbuf = optbuf + MAX_OUTPUT_SIZE;
45d60a
 	int hunksize = 0;
45d60a
 	int opthunk = 0;
45d60a
 	int hunkinc = 0;
45d60a
@@ -2132,7 +2134,14 @@ const char *pretty_print_option (option, data, len, emit_commas, emit_quotes)
45d60a
 				log_error ("Unexpected format code %c",
45d60a
 					   fmtbuf [j]);
45d60a
 			}
45d60a
+
45d60a
 			op += strlen (op);
45d60a
+			if (op >= endbuf) {
45d60a
+				log_error ("Option data exceeds"
45d60a
+					   " maximum size %d", MAX_OUTPUT_SIZE);
45d60a
+					   return ("<error>");
45d60a
+			}
45d60a
+
45d60a
 			if (dp == data + len)
45d60a
 				break;
45d60a
 			if (j + 1 < numelem && comma != ':')