Blame SOURCES/dhcp-4.3.6-options_overflow.patch

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