687b7c
diff -up rrdtool-1.4.8/src/rrd_graph.c.orig2 rrdtool-1.4.8/src/rrd_graph.c
687b7c
--- rrdtool-1.4.8/src/rrd_graph.c.orig2	2013-05-23 09:55:07.000000000 +0200
687b7c
+++ rrdtool-1.4.8/src/rrd_graph.c	2013-06-03 15:56:35.820593192 +0200
687b7c
@@ -4022,6 +4022,12 @@ rrd_info_t *rrd_graph_v(
687b7c
         char     *path;
687b7c
         char     *filename;
687b7c
 
687b7c
+        if (bad_format_imginfo(im.imginfo)) {
687b7c
+            rrd_info_free(im.grinfo);
687b7c
+            im_free(&im);
687b7c
+            rrd_set_error("bad format for imginfo");
687b7c
+            return NULL;
687b7c
+        }
687b7c
         path = strdup(im.graphfile);
687b7c
         filename = basename(path);
687b7c
         info.u_str =
687b7c
@@ -4827,6 +4833,51 @@ int bad_format(
687b7c
 }
687b7c
 
687b7c
 
687b7c
+int bad_format_imginfo(
687b7c
+    char *fmt)
687b7c
+{
687b7c
+    char     *ptr;
687b7c
+    int       n = 0;
687b7c
+
687b7c
+    ptr = fmt;
687b7c
+    while (*ptr != '\0')
687b7c
+        if (*ptr++ == '%') {
687b7c
+
687b7c
+            /* line cannot end with percent char */
687b7c
+            if (*ptr == '\0')
687b7c
+                return 1;
687b7c
+            /* '%%' is allowed */
687b7c
+            if (*ptr == '%')
687b7c
+                ptr++;
687b7c
+            /* '%s', '%S' are allowed */
687b7c
+            else if (*ptr == 's' || *ptr == 'S') {
687b7c
+                n = 1;
687b7c
+                ptr++;
687b7c
+            }
687b7c
+
687b7c
+            /* or else '% 4lu' and such are allowed */
687b7c
+            else {
687b7c
+                /* optional padding character */
687b7c
+                if (*ptr == ' ')
687b7c
+                    ptr++;
687b7c
+                /* This should take care of 'm' */
687b7c
+                while (*ptr >= '0' && *ptr <= '9')
687b7c
+                    ptr++;
687b7c
+                /* 'lu' must follow here */
687b7c
+                if (*ptr++ != 'l')
687b7c
+                    return 1;
687b7c
+                if (*ptr == 'u')
687b7c
+                    ptr++;
687b7c
+                else
687b7c
+                    return 1;
687b7c
+                n++;
687b7c
+            }
687b7c
+        }
687b7c
+
687b7c
+    return (n != 3);
687b7c
+}
687b7c
+
687b7c
+
687b7c
 int vdef_parse(
687b7c
     struct graph_desc_t
687b7c
     *gdes,