]> granicus.if.org Git - graphviz/commitdiff
agwrite: fix: ignore out of range 'linelength'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 25 Feb 2022 16:09:36 +0000 (08:09 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 27 Feb 2022 21:12:12 +0000 (13:12 -0800)
This code was accepting large negative numbers and then converting them to
positive numbers that were applied as the line length limit. This seems clearly
unintended. This rephrasing now ignores any out of range value set for
`linelength`.

lib/cgraph/write.c

index d7c46f9dda7ee61adaef723a00c9521c34423f7c..438cd8c262aa6196d3524bdba74af423dfe57ca4 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
+#include <limits.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>             /* need sprintf() */
@@ -655,13 +656,12 @@ static void set_attrwf(Agraph_t * g, bool toplevel, bool value)
 int agwrite(Agraph_t * g, void *ofile)
 {
     char* s;
-    int len;
     Level = 0;                 /* re-initialize tab level */
     s = agget(g, "linelength");
     if (s != NULL && isdigit((int)*s)) {
-       len = (int)strtol(s, (char **)NULL, 10);
-       if (len == 0 || len >= MIN_OUTPUTLINE)
-           Max_outputline = len;
+       unsigned long len = strtoul(s, NULL, 10);
+       if ((len == 0 || len >= MIN_OUTPUTLINE) && len <= (unsigned long)INT_MAX)
+           Max_outputline = (int)len;
     }
     set_attrwf(g, true, false);
     CHKRV(write_hdr(g, ofile, TRUE));