Blame SOURCES/dhcp-4.2.5-options_overflow.patch

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