From 3014af50b22f1be89b5514faea284de7b63fa5dc Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Wed, 31 Aug 2022 21:37:44 +0200
Subject: [PATCH] Clean up attributes in source doc

Also make bit flag constants unsigned to avoid implicit-conversion
warnings.

CVE: CVE-2023-40403
Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/libxslt/-/commit/452fb4ca9b9803448826008b9573987c615912a1]
Signed-off-by: Hitendra Prajapati <hprajapati@mvista.com>

---
 libxslt/transform.c | 10 ++++++++++
 libxslt/xsltutils.h |  6 +++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libxslt/transform.c b/libxslt/transform.c
index 19d7326..7299eb5 100644
--- a/libxslt/transform.c
+++ b/libxslt/transform.c
@@ -5764,6 +5764,16 @@ xsltCleanupSourceDoc(xmlDocPtr doc) {
         if (psviPtr)
             *psviPtr = NULL;
 
+        if (cur->type == XML_ELEMENT_NODE) {
+            xmlAttrPtr prop = cur->properties;
+
+            while (prop) {
+                prop->atype &= ~(XSLT_SOURCE_NODE_MASK << 27);
+                prop->psvi = NULL;
+                prop = prop->next;
+            }
+        }
+
         if (cur->children != NULL && cur->type != XML_ENTITY_REF_NODE) {
             cur = cur->children;
         } else {
diff --git a/libxslt/xsltutils.h b/libxslt/xsltutils.h
index 6c14ecf..2af4282 100644
--- a/libxslt/xsltutils.h
+++ b/libxslt/xsltutils.h
@@ -248,9 +248,9 @@ XSLTPUBFUN xmlXPathCompExprPtr XSLTCALL
 						 int flags);
 
 #ifdef IN_LIBXSLT
-#define XSLT_SOURCE_NODE_MASK       15
-#define XSLT_SOURCE_NODE_HAS_KEY    1
-#define XSLT_SOURCE_NODE_HAS_ID     2
+#define XSLT_SOURCE_NODE_MASK       15u
+#define XSLT_SOURCE_NODE_HAS_KEY    1u
+#define XSLT_SOURCE_NODE_HAS_ID     2u
 int
 xsltGetSourceNodeFlags(xmlNodePtr node);
 int
