#1035558 libxml2-utils: xmllint ignores --output option and writes to stdout

Package:
libxml2-utils
Source:
libxml2-utils
Description:
GNOME XML library - utilities
Submitter:
Tj
Date:
2024-02-21 06:15:04 UTC
Severity:
normal
Tags:
#1035558#5
Date:
2023-05-05 11:59:41 UTC
From:
To:
I've done some follow-up debugging (on upstream git) to be sure the
problem seems to exist upstream - unless I'm severely misunderstanding
what --output is supposed to do. Anyhow; the trace shows it reaches
doXPathDump(). Note that 'buf' is hard-coded to use stdout. The call to
xmlOutputBufferClose(buf) causes the output to be sent. In gdb I confirm
'output' is set immediately after that:

$ gdb -directory /srv/NAS/Sunny/SourceCode/libxml2/libxml2 -args
/srv/NAS/Sunny/SourceCode/libxml2/libxml2/.libs/xmllint --output
test.txt --html --xpath '//div[contains(@class,
'\''test'\'')]/div/ul/li/a/@href' xmllint-test.html

2038                break;
(gdb) p output
$1 = 0x7fffffffe1d5 "test.txt"

xmllint.c:

static void doXPathDump(xmlXPathObjectPtr cur) {
     switch(cur->type) {
         case XPATH_NODESET: {
             int i;
             xmlNodePtr node;
#ifdef LIBXML_OUTPUT_ENABLED
             xmlOutputBufferPtr buf;

             if ((cur->nodesetval == NULL) || (cur->nodesetval->nodeNr
<= 0)) {
                 if (!quiet) {
                     fprintf(stderr, "XPath set is empty\n");
                 }
                 break;
             }
             buf = xmlOutputBufferCreateFile(stdout, NULL);
             if (buf == NULL) {
                 fprintf(stderr, "Out of memory for XPath\n");
                 progresult = XMLLINT_ERR_MEM;
                 return;
             }
             for (i = 0;i < cur->nodesetval->nodeNr;i++) {
                 node = cur->nodesetval->nodeTab[i];
                 xmlNodeDumpOutput(buf, NULL, node, 0, 0, NULL);
                 xmlOutputBufferWrite(buf, 1, "\n");
             }
             xmlOutputBufferClose(buf);

#1035558#10
Date:
2023-05-05 14:24:38 UTC
From:
To:
Apologies - email client didn't fill the correct address. This was a
reply to bug #1035554

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035554

This can be closed!