Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-74345

"oscap xccdf eval" fails with exit code 1 after printing "No bytes exported: xmlCode: -<randomvalue?>."

Linking RHIVOS CVEs to...Migration: Automation ...SWIFT: POC ConversionSync from "Extern...XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done-Errata
    • Icon: Undefined Undefined
    • rhel-8.10.z
    • rhel-8.10
    • libxml2
    • libxml2-2.9.7-21.el8_10
    • No
    • Moderate
    • rhel-display-desktop-foundation
    • ssg_display
    • None
    • False
    • False
    • Hide

      None

      Show
      None
    • None
    • Red Hat Enterprise Linux
    • None
    • None

      This is a continuation of RHEL-74343 but very likely unrelated.

      What were you trying to do that didn't work?

      A customer, when scanning his system using Satellite-generated XML files passed to oscap, gets unexpected exit code 1 instead of exit code 2.
      The reason for this is the XML dumper fails somehow with the following error message:

      W: oscap: No bytes exported: xmlCode: -2122330465.
      

      The XML result file looks however complete.
      The xmlCode value seems somehow random (for another run it was -2117728052).

      Internally oscap makes use of xmlSaveFormatFileEnc(), xmlSaveFormatFileTo() and xmlOutputBufferClose() functions will all claim to return -1 on error, but apparently it's not the case:

      1. oscap code
        221 int oscap_xml_save_filename(const char *filename, xmlDocPtr doc)
        222 {
        223         xmlOutputBufferPtr buff;
        224         int xmlCode;
        225 
        226         if (strcmp(filename, "-") == 0) {
        227 >>>>            xmlCode = xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1);
        228         }
        229         else {
        230                 int fd = oscap_open_writable(filename);
         :
        241 
        242 >>>>            xmlCode = xmlSaveFormatFileTo(buff, doc, "UTF-8", 1);
        243                 close(fd);
        244         }
        245         if (xmlCode <= 0) {
        246                 oscap_setxmlerr(xmlGetLastError());
        247                 dW("No bytes exported: xmlCode: %d.", xmlCode);
        248         }
        
      1. libxml2 code
        2673 /**
        2674  * xmlSaveFormatFileEnc:
        2675  * @filename:  the filename or URL to output
        2676  * @cur:  the document being saved
        2677  * @encoding:  the name of the encoding to use or NULL.
        2678  * @format:  should formatting spaces be added.
        2679  *
        2680  * Dump an XML document to a file or an URL.
        2681  *
        2682  * Returns the number of bytes written or -1 in case of error.
        2683  * Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1
        2684  * or xmlKeepBlanksDefault(0) was called
        2685  */
        2686 int
        2687 xmlSaveFormatFileEnc( const char * filename, xmlDocPtr cur,
        2688                         const char * encoding, int format ) {
         :
        
        
        2633 /**
        2634  * xmlSaveFormatFileTo:
        2635  * @buf:  an output I/O buffer
        2636  * @cur:  the document
        2637  * @encoding:  the encoding if any assuming the I/O layer handles the trancoding
        2638  * @format: should formatting spaces been added
        2639  *
        2640  * Dump an XML document to an I/O buffer.
        2641  * Warning ! This call xmlOutputBufferClose() on buf which is not available
        2642  * after this call.
        2643  *
        2644  * returns: the number of bytes written or -1 in case of failure.
        2645  */
        2646 int
        2647 xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur,
        2648                     const char *encoding, int format)
        2649 {
         :
        2669     ret = xmlOutputBufferClose(buf);
        2670     return (ret);
        2671 }
        
        
        2485 /**
        2486  * xmlOutputBufferClose:
        2487  * @out:  a buffered output
        2488  *
        2489  * flushes and close the output I/O channel
        2490  * and free up all the associated resources
        2491  *
        2492  * Returns the number of byte written or -1 in case of error.
        2493  */
        2494 int
        2495 xmlOutputBufferClose(xmlOutputBufferPtr out)
        2496 {
         :
        

      What is the impact of this issue to you?

      Cannot assess the system since "exit code 1" means "other error".

      Please provide the package NVR for which the bug is seen:

      openscap-scanner-1.3.8-1.el8_8.x86_64
      libxml2-2.9.7-16.el8_8.1.x86_64

      How reproducible is this bug?:

      Always on customer system
      I cannot reproduce myself

      Steps to reproduce

      # oscap xccdf eval  --profile xccdf_org.ssgproject.content_profile_cis_customized --tailoring-file 250a6a12df56e12e1e884a60ae5a2d3e7c0778752f05108517824eaef23d70f3.xml --results-arf /tmp/results.xml cbe486454b7006c73d360a8ca347ecf14aa97456e137de1876a2637292a886a2.xml
      

      Files are available in ATTACH-15335 (other JIRA).

      Expected results

      No warning.

      Actual results

      Warning causing oscap to fail with exit code 1.

              dking@redhat.com David King
              rhn-support-rmetrich Renaud Métrich
              David King David King
              Vera Cholasta Vera Cholasta
              Votes:
              1 Vote for this issue
              Watchers:
              14 Start watching this issue

                Created:
                Updated:
                Resolved: