Blame SOURCES/dhcp-4.3.6-options_overflow.patch

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