Skip to content

Commit 5425df8

Browse files
committed
Merge commit '3b1742b8391e966be780bdc43fdf959f7b3a118c'
2 parents eb4f611 + 3b1742b commit 5425df8

File tree

13 files changed

+101
-14
lines changed

13 files changed

+101
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ if(LIBXML2_WITH_TESTS)
528528
endif()
529529
add_test(NAME testchar COMMAND testchar)
530530
add_test(NAME testdict COMMAND testdict)
531-
add_test(NAME testparser COMMAND testparser)
531+
add_test(NAME testparser COMMAND testparser WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
532532
add_test(NAME testrecurse COMMAND testrecurse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
533533
add_test(NAME testThreads COMMAND testThreads WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
534534
endif()

NEWS

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
NEWS file for libxml2
22

3+
v2.13.3: Jul 24 2024
4+
5+
### Security
6+
7+
- [CVE-2024-40896] Fix XXE protection in downstream code
8+
9+
### Regressions
10+
11+
- autotools: Use AC_CHECK_DECL to check for getentropy
12+
- xinclude: Fix fallback for text includes
13+
- io: Don't call getcwd in xmlParserGetDirectory
14+
- io: Fix return value of xmlFileRead
15+
- parser: Fix error return of xmlParseBalancedChunkMemory
16+
17+
### Improvements
18+
19+
- xinclude: Set error handler when parsing text
20+
- Undeprecate xmlKeepBlanksDefault
21+
22+
323
v2.13.2: Jul 4 2024
424

525
### Regressions

configure.ac

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ AC_PREREQ([2.63])
33

44
m4_define([MAJOR_VERSION], 2)
55
m4_define([MINOR_VERSION], 13)
6-
m4_define([MICRO_VERSION], 2)
6+
m4_define([MICRO_VERSION], 3)
77

88
AC_INIT([libxml2],[MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION])
99
AC_CONFIG_SRCDIR([entities.c])
@@ -310,13 +310,17 @@ AC_CHECK_HEADERS([glob.h])
310310
AM_CONDITIONAL(WITH_GLOB, test "$ac_cv_header_glob_h" = "yes")
311311

312312
dnl Checks for library functions.
313-
AC_CHECK_FUNCS([getentropy gettimeofday ftime stat mmap munmap])
313+
AC_CHECK_FUNCS([gettimeofday ftime stat mmap munmap])
314314

315315
AH_VERBATIM([HAVE_MUNMAP_AFTER],[/* mmap() is no good without munmap() */
316316
#if defined(HAVE_MMAP) && !defined(HAVE_MUNMAP)
317317
# undef /**/ HAVE_MMAP
318318
#endif])
319319

320+
AC_CHECK_DECL([getentropy],
321+
[AC_DEFINE([HAVE_GETENTROPY], [1], [getentropy])], [],
322+
[#include <sys/random.h>])
323+
320324
dnl
321325
dnl Checks for inet libraries
322326
dnl

include/libxml/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ XML_DEPRECATED XMLPUBFUN int
948948
xmlSubstituteEntitiesDefault(int val);
949949
XML_DEPRECATED XMLPUBFUN int
950950
xmlThrDefSubstituteEntitiesDefaultValue(int v);
951-
XML_DEPRECATED XMLPUBFUN int
951+
XMLPUBFUN int
952952
xmlKeepBlanksDefault (int val);
953953
XML_DEPRECATED XMLPUBFUN int
954954
xmlThrDefKeepBlanksDefaultValue(int v);

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(
22
'libxml2',
33
'c',
4-
version: '2.13.2',
4+
version: '2.13.3',
55
license: 'MIT',
66
default_options: ['buildtype=debug', 'warning_level=3'],
77
meson_version: '>= 0.61',

parser.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7382,6 +7382,14 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
73827382
return;
73837383
}
73847384

7385+
/*
7386+
* Some users try to parse entities on their own and used to set
7387+
* the renamed "checked" member. Fix the flags to cover this
7388+
* case.
7389+
*/
7390+
if (((ent->flags & XML_ENT_PARSED) == 0) && (ent->children != NULL))
7391+
ent->flags |= XML_ENT_PARSED;
7392+
73857393
/*
73867394
* The first reference to the entity trigger a parsing phase
73877395
* where the ent->children is filled with the result from
@@ -12535,7 +12543,10 @@ xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax,
1253512543
else
1253612544
xmlFreeNodeList(list);
1253712545

12538-
ret = ctxt->errNo;
12546+
if (!ctxt->wellFormed)
12547+
ret = ctxt->errNo;
12548+
else
12549+
ret = XML_ERR_OK;
1253912550

1254012551
xmlFreeInputStream(input);
1254112552
xmlFreeParserCtxt(ctxt);

result/XInclude/fallback8.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<doc>
3+
text not found
4+
</doc>

result/XInclude/fallback8.xml.err

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I/O warning : failed to load "test/XInclude/docs/404.txt": No such file or directory

result/XInclude/fallback8.xml.rdr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
0 1 doc 0 0
2+
1 14 #text 0 1
3+
4+
1 3 #text 0 1 text not found
5+
1 14 #text 0 1
6+
7+
0 15 doc 0 0

test/XInclude/docs/fallback8.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<doc>
3+
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="404.txt" parse="text">
4+
<xi:fallback>text not found</xi:fallback>
5+
</xi:include>
6+
</doc>
7+

testparser.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See Copyright for the status of this software.
55
*/
66

7+
#define XML_DEPRECATED
8+
79
#include <libxml/parser.h>
810
#include <libxml/uri.h>
911
#include <libxml/xmlreader.h>
@@ -95,6 +97,34 @@ testNodeGetContent(void) {
9597
return err;
9698
}
9799

100+
static int
101+
testCFileIO(void) {
102+
xmlDocPtr doc;
103+
int err = 0;
104+
105+
/* Deprecated FILE-based API */
106+
xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen, xmlFileRead,
107+
xmlFileClose);
108+
doc = xmlReadFile("test/ent1", NULL, 0);
109+
110+
if (doc == NULL) {
111+
err = 1;
112+
} else {
113+
xmlNodePtr root = xmlDocGetRootElement(doc);
114+
115+
if (root == NULL || !xmlStrEqual(root->name, BAD_CAST "EXAMPLE"))
116+
err = 1;
117+
}
118+
119+
xmlFreeDoc(doc);
120+
xmlPopInputCallbacks();
121+
122+
if (err)
123+
fprintf(stderr, "xmlReadFile failed with FILE input callbacks\n");
124+
125+
return err;
126+
}
127+
98128
#ifdef LIBXML_SAX1_ENABLED
99129
static int
100130
testBalancedChunk(void) {
@@ -540,6 +570,7 @@ main(void) {
540570
err |= testStandaloneWithEncoding();
541571
err |= testUnsupportedEncoding();
542572
err |= testNodeGetContent();
573+
err |= testCFileIO();
543574
#ifdef LIBXML_SAX1_ENABLED
544575
err |= testBalancedChunk();
545576
#endif

xinclude.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,11 +1653,18 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, xmlXIncludeRefPtr ref) {
16531653
xmlXIncludeErrMemory(ctxt);
16541654
goto error;
16551655
}
1656+
if (ctxt->errorHandler != NULL)
1657+
xmlCtxtSetErrorHandler(pctxt, ctxt->errorHandler, ctxt->errorCtxt);
16561658
inputStream = xmlLoadExternalEntity((const char*)url, NULL, pctxt);
16571659
if (inputStream == NULL) {
1660+
/*
1661+
* ENOENT only produces a warning which isn't reflected in errNo.
1662+
*/
16581663
if (pctxt->errNo == XML_ERR_NO_MEMORY)
16591664
xmlXIncludeErrMemory(ctxt);
1660-
else
1665+
else if ((pctxt->errNo != XML_ERR_OK) &&
1666+
(pctxt->errNo != XML_IO_ENOENT) &&
1667+
(pctxt->errNo != XML_IO_UNKNOWN))
16611668
xmlXIncludeErr(ctxt, NULL, pctxt->errNo, "load error", NULL);
16621669
goto error;
16631670
}

xmlIO.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ xmlFileRead(void * context, char * buffer, int len) {
776776
if ((bytes < (size_t) len) && (ferror(file)))
777777
return(-xmlIOErr(0, "fread()"));
778778

779-
return(len);
779+
return(bytes);
780780
}
781781

782782
#ifdef LIBXML_OUTPUT_ENABLED
@@ -2903,13 +2903,8 @@ xmlParserGetDirectory(const char *filename) {
29032903
if (cur == dir) dir[1] = 0;
29042904
else *cur = 0;
29052905
ret = xmlMemStrdup(dir);
2906-
#if !defined(WINAPI_FAMILY_PARTITION) || !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
29072906
} else {
2908-
if (getcwd(dir, 1024) != NULL) {
2909-
dir[1023] = 0;
2910-
ret = xmlMemStrdup(dir);
2911-
}
2912-
#endif
2907+
ret = xmlMemStrdup(".");
29132908
}
29142909
return(ret);
29152910
#undef IS_XMLPGD_SEP

0 commit comments

Comments
 (0)