]> wimlib.net Git - wimlib/commitdiff
xml.c: Fix writing <WINDOWS> element
authorEric Biggers <ebiggers3@gmail.com>
Sat, 7 Dec 2013 00:40:57 +0000 (18:40 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 7 Dec 2013 19:40:32 +0000 (13:40 -0600)
A positive return value of xmlTextWriterEndElement would be incorrectly
passed up the call chain, causing an unexpected error when writing the
XML data.

src/integrity.c
src/lookup_table.c
src/write.c
src/xml.c

index 0bfb80501c8c8f66987617ebbe13e8460573afa7..b83b9c06279b642cbcd7e8631cc806d47a603eef 100644 (file)
@@ -328,6 +328,10 @@ write_integrity_table(WIMStruct *wim,
        int ret;
        u32 new_table_size;
 
+       DEBUG("Writing integrity table "
+             "(new_lookup_table_end=%"PRIu64", old_lookup_table_end=%"PRIu64")",
+             new_lookup_table_end, old_lookup_table_end);
+
        wimlib_assert(old_lookup_table_end <= new_lookup_table_end);
 
        old_table = NULL;
@@ -368,6 +372,7 @@ write_integrity_table(WIMStruct *wim,
        FREE(new_table);
 out_free_old_table:
        FREE(old_table);
+       DEBUG("ret=%d", ret);
        return ret;
 }
 
index 9109c481771fa1166e85220d53dc442fef3e6ca4..553cf33b1c413f4dbfa430291b8439b85abec869 100644 (file)
@@ -716,6 +716,7 @@ write_wim_lookup_table_from_stream_list(struct list_head *stream_list,
                                             write_resource_flags,
                                             comp_ctx);
        FREE(table_buf);
+       DEBUG("ret=%d", ret);
        return ret;
 }
 
index 6c97c79604823415a831f7a7fecc303195f1ec9d..d728e5458e3f48018725dbd41545f28082631902 100644 (file)
@@ -2140,10 +2140,12 @@ close_wim_writable(WIMStruct *wim, int write_flags)
 {
        int ret = 0;
 
-       if (!(write_flags & WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR))
+       if (!(write_flags & WIMLIB_WRITE_FLAG_FILE_DESCRIPTOR)) {
+               DEBUG("Closing WIM file.");
                if (filedes_valid(&wim->out_fd))
                        if (filedes_close(&wim->out_fd))
                                ret = WIMLIB_ERR_WRITE;
+       }
        filedes_invalidate(&wim->out_fd);
        return ret;
 }
@@ -2206,6 +2208,8 @@ finish_write(WIMStruct *wim, int image, int write_flags,
        off_t new_lookup_table_end;
        u64 xml_totalbytes;
 
+       DEBUG("image=%d, write_flags=%08x", image, write_flags);
+
        write_resource_flags = write_flags_to_resource_flags(write_flags);
 
        /* In the WIM header, there is room for the resource entry for a
@@ -2280,6 +2284,7 @@ finish_write(WIMStruct *wim, int image, int write_flags,
        hdr_offset = 0;
        if (write_flags & WIMLIB_WRITE_FLAG_HEADER_AT_END)
                hdr_offset = wim->out_fd.offset;
+       DEBUG("Writing new header @ %"PRIu64".", hdr_offset);
        ret = write_wim_header_at_offset(&wim->hdr, &wim->out_fd, hdr_offset);
        if (ret)
                return ret;
@@ -2291,6 +2296,7 @@ finish_write(WIMStruct *wim, int image, int write_flags,
         * operation has been written to disk, but the new file data has not.
         */
        if (write_flags & WIMLIB_WRITE_FLAG_FSYNC) {
+               DEBUG("Syncing WIM file.");
                if (fsync(wim->out_fd.fd)) {
                        ERROR_WITH_ERRNO("Error syncing data to WIM file");
                        return WIMLIB_ERR_WRITE;
@@ -2687,6 +2693,7 @@ write_wim_part(WIMStruct *wim,
 out_restore_hdr:
        memcpy(&wim->hdr, &hdr_save, sizeof(struct wim_header));
        (void)close_wim_writable(wim, write_flags);
+       DEBUG("ret=%d", ret);
        return ret;
 }
 
index b22bc0945f4e9466ee4dac2f41a49ce9a2bf0a59..5258aaf4cfacb7275e1d8203195668b09680c20d 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -752,7 +752,11 @@ xml_write_windows_version(xmlTextWriter *writer,
        if (rc < 0)
                return rc;
 
-       return xmlTextWriterEndElement(writer); /* </VERSION> */
+       rc = xmlTextWriterEndElement(writer); /* </VERSION> */
+       if (rc < 0)
+               return rc;
+
+       return 0;
 }
 
 /* Writes the information contained in a `struct windows_info' to the XML
@@ -802,16 +806,19 @@ xml_write_windows_info(xmlTextWriter *writer,
 
        if (windows_info->windows_version_exists) {
                rc = xml_write_windows_version(writer, &windows_info->windows_version);
-               if (rc < 0)
+               if (rc)
                        return rc;
        }
 
-       rc = xml_write_string(writer, "SYSTEMROOT",
-                             windows_info->system_root);
+       rc = xml_write_string(writer, "SYSTEMROOT", windows_info->system_root);
        if (rc)
                return rc;
 
-       return xmlTextWriterEndElement(writer); /* </WINDOWS> */
+       rc = xmlTextWriterEndElement(writer); /* </WINDOWS> */
+       if (rc < 0)
+               return rc;
+
+       return 0;
 }
 
 /* Writes a time element to the XML document being constructed in memory. */
@@ -897,6 +904,7 @@ xml_write_image_info(xmlTextWriter *writer, const struct image_info *image_info)
        rc = xmlTextWriterEndElement(writer); /* </IMAGE> */
        if (rc < 0)
                return rc;
+
        return 0;
 }
 
@@ -1480,6 +1488,7 @@ out_output_buffer_close:
 out_buffer_free:
        xmlBufferFree(buf);
 out:
+       DEBUG("ret=%d", ret);
        return ret;
 
 out_write_error:
@@ -1518,6 +1527,7 @@ write_wim_xml_data(WIMStruct *wim, int image, u64 total_bytes,
                                             write_resource_flags,
                                             &wim->lzx_context);
        FREE(xml_data);
+       DEBUG("ret=%d");
        return ret;
 }