Skip to content

Commit

Permalink
Roll libxslt from ef14b02c to 0203b5c5
Browse files Browse the repository at this point in the history
2022-12-17 wellnhofer@aevum.de xsltutils: Another fix to xsltComputeSortResult
2022-12-13 wellnhofer@aevum.de xsltutils: Fix regression in xsltComputeSortResult
2022-12-12 arichardson@FreeBSD.org cmake: link against libm on UNIX systems
2022-11-05 zhangnan134@huawei.com fix typo
2022-11-18 fanc999@yahoo.com.tw build: Add a distutils-based build system for the Python bits
2022-03-09 fanchunwei@src.gnome.org CMake: Relax check for Python 3.x support on Windows
2022-11-21 fanchunwei@src.gnome.org python/types.c: Fix building against older libxml2
2022-03-09 fanchunwei@src.gnome.org python/libxslt.c: Replace ssize_t with Py_ssize_t
2022-10-31 wellnhofer@aevum.de gitlab-ci: Reenable MSan and LeakSanitizer
2022-10-31 wellnhofer@aevum.de tests: Fix memory leak in runtest.c
2022-10-31 wellnhofer@aevum.de warnings: Fix strict prototypes warning
2022-09-21 ddkilzer@apple.com xsltEvalUserParams() and xsltQuoteUserParams() are susceptible to integer overflow when iterating through const char** array

Bug: 934413
Change-Id: Ie4907f4c1fbba6572cb32a5a3e484b65a936daef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4089890
Commit-Queue: Stephen Chenney <schenney@chromium.org>
Auto-Submit: Joey Arhar <jarhar@chromium.org>
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084959}
  • Loading branch information
josepharhar authored and Chromium LUCI CQ committed Dec 19, 2022
1 parent 55af768 commit c62559d
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 85 deletions.
2 changes: 1 addition & 1 deletion third_party/libxslt/README.chromium
@@ -1,6 +1,6 @@
Name: libxslt
URL: http://xmlsoft.org/XSLT
Version: 99dfc53198b374719661de6a77ef9531f2805485
Version: 0203b5c5fa9c2d8197e0df7b6fd131be855ef173
CPEPrefix: cpe:/a:xmlsoft:libxslt:1.1.37
Security Critical: yes
License: MIT
Expand Down
21 changes: 16 additions & 5 deletions third_party/libxslt/src/CMakeLists.txt
Expand Up @@ -59,10 +59,16 @@ endif()
if(LIBXSLT_WITH_PYTHON)
check_include_files(unistd.h HAVE_UNISTD_H)
check_symbol_exists(F_GETFL fcntl.h HAVE_F_GETFL)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
#set(LIBXSLT_PYTHON_INSTALL_DIR ${Python_SITEARCH} CACHE PATH "Python bindings install directory")
set(LIBXSLT_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/python"
CACHE PATH "Python bindings install directory")
if(WIN32 OR (HAVE_UNISTD_H AND HAVE_F_GETFL))
find_package(Python COMPONENTS Interpreter Development REQUIRED)
else()
find_package(Python2 COMPONENTS Interpreter Development REQUIRED)
add_library(Python::Python ALIAS Python2::Python)
set(Python_EXECUTABLE ${Python2_EXECUTABLE})
set(Python_SITEARCH ${Python2_SITEARCH})
endif()
#set(LIBXSLT_PYTHON_INSTALL_DIR ${Python_SITEARCH} CACHE PATH "Python bindings install directory")
set(LIBXSLT_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/python" CACHE PATH "Python bindings install directory")
endif()

if(LIBXSLT_WITH_THREADS)
Expand Down Expand Up @@ -307,6 +313,11 @@ if(LIBXSLT_WITH_CRYPTO AND NOT WIN32)
set(LIBGCRYPT_LIBS "-lgcrypt")
endif()

if(UNIX)
target_link_libraries(LibExslt PRIVATE m)
set(LIBM "-lm")
endif()

target_link_libraries(LibExslt PUBLIC LibXslt LibXml2::LibXml2)

set_target_properties(
Expand Down Expand Up @@ -500,7 +511,7 @@ set(XSLT_PRIVATE_LIBS "${LIBM}")

set(EXSLT_INCLUDEDIR "-I\${includedir}")
set(EXSLT_LIBDIR "-L\${libdir}")
set(EXSLT_PRIVATE_LIBS "${XSLT_PRIVATE_LIBS} ${LIBGCRYPT_LIBS}")
set(EXSLT_PRIVATE_LIBS "${XSLT_PRIVATE_LIBS} ${LIBGCRYPT_LIBS} ${LIBM}")

file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
string(REGEX REPLACE "/$" "" PACKAGE_RELATIVE_PATH "${PACKAGE_RELATIVE_PATH}")
Expand Down
1 change: 1 addition & 0 deletions third_party/libxslt/src/configure.ac
Expand Up @@ -549,6 +549,7 @@ libexslt/Makefile
libexslt/exsltconfig.h
xsltproc/Makefile
python/Makefile
python/setup.py
python/tests/Makefile
tests/Makefile
tests/xmlspec/Makefile
Expand Down
2 changes: 1 addition & 1 deletion third_party/libxslt/src/libxslt/transform.c
Expand Up @@ -492,7 +492,7 @@ void xsltDebugSetDefaultTrace(xsltDebugTraceCodes val) {
*
* Returns the current default debug tracing level mask
*/
xsltDebugTraceCodes xsltDebugGetDefaultTrace() {
xsltDebugTraceCodes xsltDebugGetDefaultTrace(void) {
return xsltDefaultTrace;
}

Expand Down
4 changes: 2 additions & 2 deletions third_party/libxslt/src/libxslt/variables.c
Expand Up @@ -1683,7 +1683,7 @@ xsltProcessUserParamInternal(xsltTransformContextPtr ctxt,

int
xsltEvalUserParams(xsltTransformContextPtr ctxt, const char **params) {
int indx = 0;
size_t indx = 0;
const xmlChar *name;
const xmlChar *value;

Expand Down Expand Up @@ -1713,7 +1713,7 @@ xsltEvalUserParams(xsltTransformContextPtr ctxt, const char **params) {

int
xsltQuoteUserParams(xsltTransformContextPtr ctxt, const char **params) {
int indx = 0;
size_t indx = 0;
const xmlChar *name;
const xmlChar *value;

Expand Down
2 changes: 1 addition & 1 deletion third_party/libxslt/src/libxslt/xslt.c
Expand Up @@ -6703,7 +6703,7 @@ xsltParseStylesheetUser(xsltStylesheetPtr style, xmlDocPtr doc) {

/**
* xsltParseStylesheetDoc:
* @doc: and xmlDoc parsed XML
* @doc: an xmlDoc parsed XML
*
* parse an XSLT stylesheet, building the associated structures. doc
* is kept as a reference within the returned stylesheet, so changes
Expand Down
140 changes: 67 additions & 73 deletions third_party/libxslt/src/libxslt/xsltutils.c
Expand Up @@ -947,10 +947,11 @@ xsltDocumentSortFunction(xmlNodeSetPtr list) {
}

/**
* xsltComputeSortResultiInternal:
* xsltComputeSortResultInternal:
* @ctxt: a XSLT process context
* @sort: node list
* @xfrm: Transform strings according to locale
* @sort: xsl:sort node
* @number: data-type is number
* @locale: transform strings according to locale
*
* reorder the current node list accordingly to the set of sorting
* requirement provided by the array of nodes.
Expand All @@ -959,11 +960,11 @@ xsltDocumentSortFunction(xmlNodeSetPtr list) {
*/
static xmlXPathObjectPtr *
xsltComputeSortResultInternal(xsltTransformContextPtr ctxt, xmlNodePtr sort,
int xfrm) {
int number, xsltLocale locale) {
#ifdef XSLT_REFACTORED
xsltStyleItemSortPtr comp;
#else
xsltStylePreCompPtr comp;
const xsltStylePreComp *comp;
#endif
xmlXPathObjectPtr *results = NULL;
xmlNodeSetPtr list = NULL;
Expand Down Expand Up @@ -1031,10 +1032,10 @@ xsltComputeSortResultInternal(xsltTransformContextPtr ctxt, xmlNodePtr sort,
if (res != NULL) {
if (res->type != XPATH_STRING)
res = xmlXPathConvertString(res);
if (comp->number)
if (number)
res = xmlXPathConvertNumber(res);
res->index = i; /* Save original pos for dupl resolv */
if (comp->number) {
if (number) {
if (res->type == XPATH_NUMBER) {
results[i] = res;
} else {
Expand All @@ -1046,9 +1047,9 @@ xsltComputeSortResultInternal(xsltTransformContextPtr ctxt, xmlNodePtr sort,
}
} else {
if (res->type == XPATH_STRING) {
if ((xfrm) && (comp->locale != (xsltLocale)0)) {
if (locale != (xsltLocale)0) {
xmlChar *str = res->stringval;
res->stringval = (xmlChar *) xsltStrxfrm(comp->locale, str);
res->stringval = (xmlChar *) xsltStrxfrm(locale, str);
xmlFree(str);
}

Expand Down Expand Up @@ -1088,7 +1089,12 @@ xsltComputeSortResultInternal(xsltTransformContextPtr ctxt, xmlNodePtr sort,
*/
xmlXPathObjectPtr *
xsltComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
return xsltComputeSortResultInternal(ctxt, sort, /* xfrm */ 0);
const xsltStylePreComp *comp = sort->psvi;
int number = 0;

if (comp != NULL)
number = comp->number;
return xsltComputeSortResultInternal(ctxt, sort, number, /* locale */ 0);
}

/**
Expand All @@ -1106,20 +1112,19 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
#ifdef XSLT_REFACTORED
xsltStyleItemSortPtr comp;
#else
xsltStylePreCompPtr comp;
const xsltStylePreComp *comp;
#endif
xmlXPathObjectPtr *resultsTab[XSLT_MAX_SORT];
xmlXPathObjectPtr *results = NULL, *res;
xmlNodeSetPtr list = NULL;
int descending, number, desc, numb;
int len = 0;
int i, j, incr;
int tst;
int depth;
xmlNodePtr node;
xmlXPathObjectPtr tmp;
int tempstype[XSLT_MAX_SORT], temporder[XSLT_MAX_SORT],
templang[XSLT_MAX_SORT];
int number[XSLT_MAX_SORT], desc[XSLT_MAX_SORT];
xsltLocale locale[XSLT_MAX_SORT];

if ((ctxt == NULL) || (sorts == NULL) || (nbsorts <= 0) ||
(nbsorts >= XSLT_MAX_SORT))
Expand All @@ -1136,71 +1141,70 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,

for (j = 0; j < nbsorts; j++) {
comp = sorts[j]->psvi;
tempstype[j] = 0;
if ((comp->stype == NULL) && (comp->has_stype != 0)) {
comp->stype =
xmlChar *stype =
xsltEvalAttrValueTemplate(ctxt, sorts[j],
(const xmlChar *) "data-type",
NULL);
if (comp->stype != NULL) {
tempstype[j] = 1;
if (xmlStrEqual(comp->stype, (const xmlChar *) "text"))
comp->number = 0;
else if (xmlStrEqual(comp->stype, (const xmlChar *) "number"))
comp->number = 1;
BAD_CAST "data-type", NULL);
number[j] = 0;
if (stype != NULL) {
if (xmlStrEqual(stype, (const xmlChar *) "text"))
;
else if (xmlStrEqual(stype, (const xmlChar *) "number"))
number[j] = 1;
else {
xsltTransformError(ctxt, NULL, sorts[j],
"xsltDoSortFunction: no support for data-type = %s\n",
comp->stype);
comp->number = 0; /* use default */
stype);
}
xmlFree(stype);
}
}
temporder[j] = 0;
} else {
number[j] = comp->number;
}
if ((comp->order == NULL) && (comp->has_order != 0)) {
comp->order = xsltEvalAttrValueTemplate(ctxt, sorts[j],
(const xmlChar *) "order",
NULL);
if (comp->order != NULL) {
temporder[j] = 1;
if (xmlStrEqual(comp->order, (const xmlChar *) "ascending"))
comp->descending = 0;
else if (xmlStrEqual(comp->order,
(const xmlChar *) "descending"))
comp->descending = 1;
xmlChar *order = xsltEvalAttrValueTemplate(ctxt, sorts[j],
BAD_CAST "order", NULL);
desc[j] = 0;
if (order != NULL) {
if (xmlStrEqual(order, (const xmlChar *) "ascending"))
;
else if (xmlStrEqual(order, (const xmlChar *) "descending"))
desc[j] = 1;
else {
xsltTransformError(ctxt, NULL, sorts[j],
"xsltDoSortFunction: invalid value %s for order\n",
comp->order);
comp->descending = 0; /* use default */
order);
}
xmlFree(order);
}
} else {
desc[j] = comp->descending;
}
templang[j] = 0;
if ((comp->lang == NULL) && (comp->has_lang != 0)) {
xmlChar *lang = xsltEvalAttrValueTemplate(ctxt, sorts[j],
(xmlChar *) "lang",
NULL);
if (lang != NULL) {
templang[j] = 1;
comp->locale = xsltNewLocale(lang);
locale[j] = xsltNewLocale(lang);
xmlFree(lang);
} else {
locale[j] = 0;
}
}
} else {
locale[j] = comp->locale;
}
}

len = list->nodeNr;

resultsTab[0] = xsltComputeSortResultInternal(ctxt, sorts[0],
/* xfrm */ 1);
resultsTab[0] = xsltComputeSortResultInternal(ctxt, sorts[0], number[0],
locale[0]);
for (i = 1;i < XSLT_MAX_SORT;i++)
resultsTab[i] = NULL;

results = resultsTab[0];

comp = sorts[0]->psvi;
descending = comp->descending;
number = comp->number;
if (results == NULL)
goto cleanup;

Expand All @@ -1215,7 +1219,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
if (results[j] == NULL)
tst = 1;
else {
if (number) {
if (number[0]) {
/* We make NaN smaller than number in accordance
with XSLT spec */
if (xmlXPathIsNaN(results[j]->floatval)) {
Expand All @@ -1232,16 +1236,16 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
results[j + incr]->floatval)
tst = 1;
else tst = -1;
} else if(comp->locale != (xsltLocale)0) {
} else if(locale[0] != (xsltLocale)0) {
tst = xsltLocaleStrcmp(
comp->locale,
locale[0],
(xsltLocaleChar *) results[j]->stringval,
(xsltLocaleChar *) results[j + incr]->stringval);
} else {
tst = xmlStrcmp(results[j]->stringval,
results[j + incr]->stringval);
}
if (descending)
if (desc[0])
tst = -tst;
}
if (tst == 0) {
Expand All @@ -1255,8 +1259,6 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
comp = sorts[depth]->psvi;
if (comp == NULL)
break;
desc = comp->descending;
numb = comp->number;

/*
* Compute the result of the next level for the
Expand All @@ -1266,7 +1268,8 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
resultsTab[depth] =
xsltComputeSortResultInternal(ctxt,
sorts[depth],
/* xfrm */ 1);
number[depth],
locale[depth]);
res = resultsTab[depth];
if (res == NULL)
break;
Expand All @@ -1276,7 +1279,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
} else if (res[j+incr] == NULL) {
tst = -1;
} else {
if (numb) {
if (number[depth]) {
/* We make NaN smaller than number in
accordance with XSLT spec */
if (xmlXPathIsNaN(res[j]->floatval)) {
Expand All @@ -1295,16 +1298,16 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
res[j + incr]->floatval)
tst = 1;
else tst = -1;
} else if(comp->locale != (xsltLocale)0) {
} else if(locale[depth] != (xsltLocale)0) {
tst = xsltLocaleStrcmp(
comp->locale,
locale[depth],
(xsltLocaleChar *) res[j]->stringval,
(xsltLocaleChar *) res[j + incr]->stringval);
} else {
tst = xmlStrcmp(res[j]->stringval,
res[j + incr]->stringval);
}
if (desc)
if (desc[depth])
tst = -tst;
}

Expand Down Expand Up @@ -1349,20 +1352,11 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
cleanup:
for (j = 0; j < nbsorts; j++) {
comp = sorts[j]->psvi;
if (tempstype[j] == 1) {
/* The data-type needs to be recomputed each time */
xmlFree((void *)(comp->stype));
comp->stype = NULL;
}
if (temporder[j] == 1) {
/* The order needs to be recomputed each time */
xmlFree((void *)(comp->order));
comp->order = NULL;
}
if (templang[j] == 1) {
xsltFreeLocale(comp->locale);
comp->locale = (xsltLocale)0;
}
if ((comp->lang == NULL) && (comp->has_lang != 0)) {
if (locale[j] != (xsltLocale)0) {
xsltFreeLocale(locale[j]);
}
}
if (resultsTab[j] != NULL) {
for (i = 0;i < len;i++)
xmlXPathFreeObject(resultsTab[j][i]);
Expand Down

0 comments on commit c62559d

Please sign in to comment.