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