From 3ab51004dabb6619e5badcb7c36bb0b83a65ecb2 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Sun, 29 Sep 2024 11:34:15 +0200 Subject: [PATCH] escape: fix error: null destination pointer --- programs/dwg2SVG.c | 3 ++- programs/escape.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/programs/dwg2SVG.c b/programs/dwg2SVG.c index 6f08eaf1e3..f932a36ced 100644 --- a/programs/dwg2SVG.c +++ b/programs/dwg2SVG.c @@ -271,7 +271,8 @@ output_TEXT (Dwg_Object *obj) obj->index, transform_X (pt.x), transform_Y (pt.y), fontfamily, text->height /* fontsize */, entity_color (obj->tio.entity), escaped ? escaped : ""); - free (escaped); + if (escaped) + free (escaped); } static void diff --git a/programs/escape.c b/programs/escape.c index eeaa8f3938..79ecede180 100644 --- a/programs/escape.c +++ b/programs/escape.c @@ -33,6 +33,8 @@ htmlescape (const char *restrict src, const Dwg_Codepage cp) return NULL; len = strlen (src) + 10; d = (char *)calloc (len, 1); + if (!d) + return NULL; s = (unsigned char *)src; dest = d; end = dest + len; @@ -93,6 +95,8 @@ htmlescape (const char *restrict src, const Dwg_Codepage cp) wc = dwg_codepage_uwc (cp, cc); if (wc > 127 || wc < 0x20) { + if (!d) + return NULL; sprintf (d, "&#x%X;", (unsigned)wc); // 4 + 4 d += strlen (d); } @@ -123,6 +127,8 @@ htmlwescape (BITCODE_TU wstr) len++; len += 16; d = dest = (char *)calloc (len, 1); + if (!d) + return NULL; while (*wstr) { @@ -174,6 +180,8 @@ htmlwescape (BITCODE_TU wstr) default: if (*wstr >= 127 || *wstr < 20) // utf8 encodings { + if (!d) + return NULL; sprintf (d, "&#x%X;", *wstr); d += strlen (d); *d = 0;