File: 0018-malloc-fail-Fix-memory-leak-in-xsltEvalGlobalVariabl.patch

package info (click to toggle)
libxslt 1.1.35-1.2%2Bdeb13u2
  • links: PTS, VCS
  • area: main
  • in suites: trixie-proposed-updates
  • size: 30,068 kB
  • sloc: xml: 75,625; ansic: 34,784; sh: 4,249; makefile: 3,128; python: 3,060; javascript: 429; perl: 34
file content (33 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
From 8e9c5d0551ab98f7f3235e9a37ef062ab76d4917 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Sun, 26 Feb 2023 16:53:44 +0100
Subject: [PATCH] malloc-fail: Fix memory leak in xsltEvalGlobalVariables

Found with libFuzzer, see #84.
---
 libxslt/variables.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libxslt/variables.c b/libxslt/variables.c
index 883b19af..c0055c21 100644
--- a/libxslt/variables.c
+++ b/libxslt/variables.c
@@ -1310,8 +1310,13 @@ xsltEvalGlobalVariables(xsltTransformContextPtr ctxt) {
 	    if (def == NULL) {
 
 		def = xsltCopyStackElem(elem);
-		xmlHashAddEntry2(ctxt->globalVars,
-				 elem->name, elem->nameURI, def);
+		if (xmlHashAddEntry2(ctxt->globalVars,
+				     elem->name, elem->nameURI, def) < 0) {
+                    xmlGenericError(xmlGenericErrorContext,
+                                    "hash update failed\n");
+                    xsltFreeStackElem(def);
+                    return(-1);
+                }
 	    } else if ((elem->comp != NULL) &&
 		       (elem->comp->type == XSLT_FUNC_VARIABLE)) {
 		/*
-- 
2.47.2