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