File: xmlrpc-c-1.59.03-use-system-expat.patch

package info (click to toggle)
xmlrpc-c 1.59.03-10.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,132 kB
  • sloc: ansic: 55,248; cpp: 13,541; sh: 3,321; makefile: 2,553; perl: 593; xml: 134
file content (232 lines) | stat: -rw-r--r-- 7,270 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
From 5d276a95a6953c51ed4fd20cabc6eab3808755e5 Mon Sep 17 00:00:00 2001
From: Sebastian Pipping <sebastian@pipping.org>
Date: Sun, 6 Apr 2025 02:19:15 +0200
Subject: [PATCH] Use system libexpat rather than bundled lib/expat/ for
 security

---
 common.mk                 | 31 +------------------------------
 config.mk.in              |  1 +
 lib/Makefile              |  3 ---
 src/Makefile              |  8 +++-----
 src/cpp/Makefile          |  6 ++----
 src/xmlrpc_expat.c        | 18 ++++++++++--------
 xmlrpc-c-config.test.main |  6 ++----
 7 files changed, 19 insertions(+), 54 deletions(-)

--- a/common.mk
+++ b/common.mk
@@ -216,22 +216,6 @@
 
 endif
 
-LIBXMLRPC_XMLTOK_DIR = $(BLDDIR)/lib/expat/xmltok
-
-ifneq ($(OMIT_XMLTOK_LIB_RULE),Y)
-LIBXMLRPC_XMLTOK         = \
-  $(call shliblefn, $(LIBXMLRPC_XMLTOK_DIR)/libxmlrpc_xmltok)
-LIBXMLRPC_XMLTOK_A       = $(LIBXMLRPC_XMLTOK_DIR)/libxmlrpc_xmltok.a
-endif
-
-LIBXMLRPC_XMLPARSE_DIR = $(BLDDIR)/lib/expat/xmlparse
-
-ifneq ($(OMIT_XMLPARSE_LIB_RULE),Y)
-LIBXMLRPC_XMLPARSE       = \
-  $(call shliblefn, $(LIBXMLRPC_XMLPARSE_DIR)/libxmlrpc_xmlparse)
-LIBXMLRPC_XMLPARSE_A     = $(LIBXMLRPC_XMLPARSE_DIR)/libxmlrpc_xmlparse.a
-endif
-
 LIBXMLRPC_ABYSS_DIR = $(BLDDIR)/lib/abyss/src
 
 ifneq ($(OMIT_ABYSS_LIB_RULE),Y)
@@ -270,16 +254,11 @@
   $(call shliblefn, $(BLDDIR)/src/cpp/libxmlrpc_server_pstream++)
 LIBXMLRPC_SERVER_PSTREAMPP_A = $(BLDDIR)/src/cpp/libxmlrpc_server_pstream++.a
 
-# LIBXMLRPC_XML is the list of Xmlrpc-c libraries we need to parse
-# XML.  If we're using an external library to parse XML, this is null.
 # LDLIBS_XML is the corresponding -L/-l options
 
 ifneq ($(ENABLE_LIBXML2_BACKEND),yes)
   # We're using the internal Expat XML parser
-  LIBXMLRPC_XML = $(LIBXMLRPC_XMLPARSE) $(LIBXMLRPC_XMLTOK)
-  LDLIBS_XML = \
-        -L$(BLDDIR)/lib/expat/xmlparse -lxmlrpc_xmlparse \
-        -L$(BLDDIR)/lib/expat/xmltok   -lxmlrpc_xmltok
+  LDLIBS_XML = $(shell $(PKG_CONFIG) --libs expat)
 else
   LDLIBS_XML = $(shell xml2-config --libs)
 endif
@@ -472,14 +451,6 @@
 	$(MAKE) -C $(dir $@) -f $(SRCDIR)/lib/libutil++/Makefile \
 	    $(notdir $@)
 
-$(LIBXMLRPC_XMLPARSE) $(LIBXMLRPC_XMLPARSE_A) : FORCE
-	$(MAKE) -C $(dir $@) -f $(SRCDIR)/lib/expat/xmlparse/Makefile \
-	    $(notdir $@)
-
-$(LIBXMLRPC_XMLTOK) $(LIBXMLRPC_XMLTOK_A) : FORCE
-	$(MAKE) -C $(dir $@) -f $(SRCDIR)/lib/expat/xmltok/Makefile \
-	    $(notdir $@)
-
 $(LIBXMLRPC_ABYSS) $(LIBXMLRPC_ABYSS_A): FORCE
 	$(MAKE) -C $(dir $@) -f $(SRCDIR)/lib/abyss/src/Makefile \
 	    $(notdir $@)
--- a/config.mk.in
+++ b/config.mk.in
@@ -52,6 +52,7 @@
 CCLD = $(CC)
 CXXLD = $(CXX)
 AR = @AR@
+PKG_CONFIG = pkg-config
 RANLIB = @RANLIB@
 LN_S = ln -s
 INSTALL = $(SRCDIR)/install-sh
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,9 +28,6 @@
 ifeq ($(MUST_BUILD_LIBWWW_CLIENT),yes)
   SUBDIRS += libwww_transport
 endif
-ifneq ($(ENABLE_LIBXML2_BACKEND),yes)
-  SUBDIRS += expat
-endif
 
 ifeq ($(HAVE_OPENSSL),Y)
   SUBDIRS += openssl
--- a/src/Makefile
+++ b/src/Makefile
@@ -73,11 +73,9 @@
   XML_PKGCONFIG_REQ = libxml-2.0
 else
   XMLRPC_XML_PARSER = xmlrpc_expat
-  XML_PARSER_LIBDEP = \
-    -Lblddir/lib/expat/xmlparse -lxmlrpc_xmlparse \
-    -Lblddir/lib/expat/xmltok -lxmlrpc_xmltok
-  XML_PARSER_LIBDEP_DEP = $(LIBXMLRPC_XMLPARSE) $(LIBXMLRPC_XMLTOK)
-  XML_PKGCONFIG_REQ = xmlrpc_expat
+  XML_PARSER_LIBDEP = $(shell $(PKG_CONFIG) expat --libs)
+  XML_PARSER_LIBDEP_DEP =
+  XML_PKGCONFIG_REQ = expat
 endif
 
 # LIBxxx_OBJS is the list of object files that make up library libxxx.
@@ -278,7 +276,7 @@
 ifeq ($(ENABLE_LIBXML2_BACKEND),yes)
   LIBXML_INCLUDES = $(shell xml2-config --cflags)
 else
-  LIBXML_INCLUDES = -Isrcdir/lib/expat/xmlparse
+  LIBXML_INCLUDES = $(shell $(PKG_CONFIG) --cflags expat)
 endif
 
 $(LIBXMLRPC_MODS:%=%.o) \
--- a/src/cpp/Makefile
+++ b/src/cpp/Makefile
@@ -42,15 +42,13 @@
 ifeq ($(ENABLE_LIBXML2_BACKEND),yes)
   LIBXML_INCLUDES = $(LIBXML2_CFLAGS)
 else
-  LIBXML_INCLUDES = -Isrcdir/lib/expat/xmlparse
+  LIBXML_INCLUDES = $(shell $(PKG_CONFIG) --cflags expat)
 endif
 
 ifeq ($(ENABLE_LIBXML2_BACKEND),yes)
   XML_PARSER_LIBDEP = $(shell xml2-config --libs)
 else
-  XML_PARSER_LIBDEP = \
-    -L$(BLDDIR)/lib/expat/xmlparse -lxmlrpc_xmlparse \
-    -L$(BLDDIR)/lib/expat/xmltok -lxmlrpc_xmltok
+  XML_PARSER_LIBDEP = $(shell $(PKG_CONFIG) --libs expat)
 endif
 
 LIBXMLRPCPP_MODS = fault global outcome param_list value xml
--- a/src/xmlrpc_expat.c
+++ b/src/xmlrpc_expat.c
@@ -6,7 +6,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <xmlparse.h> /* Expat */
+#include <expat.h>
 
 #include "bool.h"
 
@@ -419,18 +419,18 @@
 -----------------------------------------------------------------------------*/
     XML_Parser parser;
 
-    parser = xmlrpc_XML_ParserCreate(NULL);
+    parser = XML_ParserCreate(NULL);
     if (parser == NULL)
         xmlrpc_faultf(envP, "Could not create expat parser");
     else {
         initParseContext(contextP, memPoolP);
 
-        xmlrpc_XML_SetUserData(parser, contextP);
-        xmlrpc_XML_SetElementHandler(
+        XML_SetUserData(parser, contextP);
+        XML_SetElementHandler(
             parser,
             (XML_StartElementHandler) startElement,
             (XML_EndElementHandler) endElement);
-        xmlrpc_XML_SetCharacterDataHandler(
+        XML_SetCharacterDataHandler(
             parser,
             (XML_CharacterDataHandler) characterData);
     }
@@ -445,7 +445,7 @@
 
     termParseContext(contextP);
 
-    xmlrpc_XML_ParserFree(parser);
+    XML_ParserFree(parser);
 }
 
 
@@ -483,15 +483,17 @@
     if (!envP->fault_occurred) {
         bool ok;
 
-        ok = xmlrpc_XML_Parse(parser, xmlData, xmlDataLen, 1);
+        ok = XML_Parse(parser, xmlData, xmlDataLen, 1);
             /* sets 'context', *envP */
         if (!ok) {
             /* Expat failed on its own to parse it -- this is not an error
                that our handlers detected.
             */
+            const enum XML_Error error_code = XML_GetErrorCode(parser);
+            const char * const error_string = (error_code == XML_ERROR_NONE) ? NULL : XML_ErrorString(error_code);
             xmlrpc_env_set_fault(
                 envP, XMLRPC_PARSE_ERROR,
-                xmlrpc_XML_GetErrorString(parser));
+                error_string);
             if (!context.env.fault_occurred) {
                 /* Have to clean up what our handlers built before Expat
                    barfed.
--- a/xmlrpc-c-config.test.main
+++ b/xmlrpc-c-config.test.main
@@ -22,10 +22,8 @@
 if test "${ENABLE_LIBXML2_BACKEND}" = "yes"; then
   LIBXML=`xml2-config --libs`
 else
-  LIBXML="${BLDDIR}/lib/expat/xmlparse/libxmlrpc_xmlparse.a"
-  sopath="${BLDDIR}/lib/expat/xmlparse:$sopath"
-  LIBXML="${LIBXML} ${BLDDIR}/lib/expat/xmltok/libxmlrpc_xmltok.a"
-  sopath="${BLDDIR}/lib/expat/xmltok:$sopath"
+  [ -n "${PKG_CONFIG}" ] || PKG_CONFIG=pkg-config
+  LIBXML=`${PKG_CONFIG} --libs expat`
 fi
 
 needCpp=no
--- a/xmlrpc-c-config.main
+++ b/xmlrpc-c-config.main
@@ -30,7 +30,8 @@
 if test "${ENABLE_LIBXML2_BACKEND}" = "yes"; then
   LIBXML=`xml2-config --libs`
 else
-  LIBXML="-lxmlrpc_xmlparse -lxmlrpc_xmltok"
+  [ -n "${PKG_CONFIG}" ] || PKG_CONFIG=pkg-config
+  LIBXML=`${PKG_CONFIG} --libs expat`
 fi
 
 needCpp=no