From a7ac5c3ee85edd0573748e474a11a1796f985c83 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 1 Jul 2022 20:23:27 -0700 Subject: [PATCH] fix: Revert "rewrite versionStr2Version to use strtoul" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This reverts commit 5aa56175c4715700cc8bf9fecad7b27665c04379. This commit inadvertently changed the parsing of the `xdotversion` attribute to make something like “1.7” parse as version 1. Gitlab: fixes #358 --- CHANGELOG.md | 2 ++ plugin/core/gvrender_core_dot.c | 25 ++++++++++++++++++------- tests/test_regression.py | 1 - 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea59cbb5..8779a162f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - b15.gv crashes dot #827 - heap overflow in function startElementHandler in gxl2gv.c #2093 - Crash on assertion #121 +- `xdotversion` attribute is no longer misparsed. This was a regression in + Graphviz 2.47.2. #358 ## [4.0.0] – 2022-05-29 diff --git a/plugin/core/gvrender_core_dot.c b/plugin/core/gvrender_core_dot.c index 63eb5e535..93e038a87 100644 --- a/plugin/core/gvrender_core_dot.c +++ b/plugin/core/gvrender_core_dot.c @@ -14,7 +14,6 @@ #include #endif -#include #include #include #include @@ -365,14 +364,26 @@ static void xdot_end_cluster(GVJ_t * job) } static unsigned short -versionStr2Version (const char* str) +versionStr2Version (char* str) { - unsigned long u = strtoul(str, NULL, 10); - if (u == 0 || u > USHRT_MAX) { - agerr(AGWARN, "xdot version \"%s\" too long", str); - } + char c, buf[BUFSIZ]; + int n = 0; + char* s = str; + unsigned short us; - return (unsigned short)u; + while ((c = *s++)) { + if (isdigit(c)) { + if (n < BUFSIZ-1) buf[n++] = c; + else { + agerr(AGWARN, "xdot version \"%s\" too long", str); + break; + } + } + } + buf[n] = '\0'; + + us = atoi(buf); + return us; } /* diff --git a/tests/test_regression.py b/tests/test_regression.py index 744ccb874..7d97b4e60 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -307,7 +307,6 @@ def test_191(): assert p.returncode != 0, "syntax error was only a warning, not an error" -@pytest.mark.xfail(strict=True) def test_358(): """ setting xdot version to 1.7 should enable font characteristics -- 2.40.0