1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-26 00:37:43 +03:00

parser: Introduce XML_INPUT_NETWORK input flag

This allows to disable network access when creating parser inputs with
xmlInputCreateUrl.
This commit is contained in:
Nick Wellnhofer
2024-06-11 18:11:51 +02:00
parent 780e432a5c
commit ab5e6debd1
3 changed files with 13 additions and 0 deletions

View File

@@ -363,6 +363,7 @@ XMLPUBFUN xmlParserInputPtr
#define XML_INPUT_BUF_STATIC (1u << 1)
#define XML_INPUT_BUF_ZERO_TERMINATED (1u << 2)
#define XML_INPUT_UNZIP (1u << 3)
#define XML_INPUT_NETWORK (1u << 4)
XMLPUBFUN int
xmlInputCreateUrl(const char *url, int flags, xmlParserInputPtr *out);

View File

@@ -2177,6 +2177,8 @@ xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) {
*
* The flag XML_INPUT_UNZIP allows decompression.
*
* The flag XML_INPUT_NETWORK allows network access.
*
* Available since 2.14.0.
*
* Returns an xmlParserErrors code.
@@ -2235,6 +2237,8 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
if ((ctxt->options & XML_PARSE_NO_UNZIP) == 0)
flags |= XML_INPUT_UNZIP;
if ((ctxt->options & XML_PARSE_NONET) == 0)
flags |= XML_INPUT_NETWORK;
code = xmlInputCreateUrl(filename, flags, &input);
if (code != XML_ERR_OK) {
@@ -2422,6 +2426,8 @@ xmlLoadExternalEntity(const char *URL, const char *ID,
if ((ctxt->options & XML_PARSE_NO_UNZIP) == 0)
flags |= XML_INPUT_UNZIP;
if ((ctxt->options & XML_PARSE_NONET) == 0)
flags |= XML_INPUT_NETWORK;
code = ctxt->resourceLoader(ctxt->resourceCtxt, URL, ID, flags,
0, &ret);

View File

@@ -1115,6 +1115,9 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename,
#ifdef LIBXML_FTP_ENABLED
if (xmlIOFTPMatch(filename)) {
if ((flags & XML_INPUT_NETWORK) == 0)
return(XML_IO_NETWORK_ATTEMPT);
buf->context = xmlIOFTPOpen(filename);
if (buf->context != NULL) {
@@ -1127,6 +1130,9 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename,
#ifdef LIBXML_HTTP_ENABLED
if (xmlIOHTTPMatch(filename)) {
if ((flags & XML_INPUT_NETWORK) == 0)
return(XML_IO_NETWORK_ATTEMPT);
buf->context = xmlIOHTTPOpen(filename);
if (buf->context != NULL) {