From c3cc2834994eed8e3c8ea6faeac19e30c976bf16 Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 19 Jul 2024 10:19:29 +0200 Subject: [PATCH] [GRM] Fix stack buffer overflow in the `is_number` util function --- lib/grm/src/grm/dom_render/render.cxx | 4 ++-- lib/grm/src/grm/utilcpp.cxx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/grm/src/grm/dom_render/render.cxx b/lib/grm/src/grm/dom_render/render.cxx index 925d63fbf..ac05015df 100644 --- a/lib/grm/src/grm/dom_render/render.cxx +++ b/lib/grm/src/grm/dom_render/render.cxx @@ -12512,7 +12512,7 @@ static void tickLabelAdjustment(const std::shared_ptr &tick_group, char text_c[256]; format_reference_t reference = {1, 1}; int sc_format = 2; - const char minus[3] = {(char)0xe2, (char)0x88, (char)0x92}; // gr minus sign + const char minus[] = {(char)0xe2, (char)0x88, (char)0x92, '\0'}; // gr minus sign auto em_dash = std::string(minus); size_t start_pos = 0; @@ -12528,7 +12528,7 @@ static void tickLabelAdjustment(const std::shared_ptr &tick_group, snprintf(text_c, 256, "%s", without_minus.c_str()); text = gr_ftoa(text_c, atof(without_minus.c_str()), &reference); - text = em_dash + text; + if (start_pos != 0) text = em_dash + text; scientific_format = sc_format; } } diff --git a/lib/grm/src/grm/utilcpp.cxx b/lib/grm/src/grm/utilcpp.cxx index b63d55b75..410d324b2 100644 --- a/lib/grm/src/grm/utilcpp.cxx +++ b/lib/grm/src/grm/utilcpp.cxx @@ -98,7 +98,7 @@ std::complex moivre(double r, int x, int n) bool is_number(std::string_view str) { - const char minus[3] = {(char)0xe2, (char)0x88, (char)0x92}; // gr minus sign + const char minus[] = {(char)0xe2, (char)0x88, (char)0x92, '\0'}; // gr minus sign auto em_dash = std::string(minus); size_t start_pos = 0; if (starts_with(str, em_dash))