]> wimlib.net Git - wimlib/blobdiff - src/security.c
win32_capture_streams(): Handle not implemented/supported
[wimlib] / src / security.c
index 4cd898b5b4a3fa9e0cb86d3aa6f7af224f37e9fe..6ed83cd7e952a75cc50f13b091414f34cb444506 100644 (file)
@@ -28,7 +28,7 @@
 #endif
 
 #include "wimlib/assert.h"
-#include "wimlib/buffer_io.h"
+#include "wimlib/endianness.h"
 #include "wimlib/error.h"
 #include "wimlib/security.h"
 #include "wimlib/sha1.h"
@@ -146,7 +146,7 @@ struct wim_security_data_disk {
  * the validation in libntfs-3g.
  */
 static void
-empty_sacl_fixup(SECURITY_DESCRIPTOR_RELATIVE *descr, size_t *size_p)
+empty_sacl_fixup(SECURITY_DESCRIPTOR_RELATIVE *descr, u64 *size_p)
 {
        /* No-op if no NTFS-3g support, or if NTFS-3g is version 2013 or later
         * */
@@ -181,9 +181,10 @@ new_wim_security_data(void)
  * Note: There is no `offset' argument because the security data is located at
  * the beginning of the metadata resource.
  *
- * Possible errors include:
+ * Return values:
+ *     WIMLIB_ERR_SUCCESS (0)
+ *     WIMLIB_ERR_INVALID_METADATA_RESOURCE
  *     WIMLIB_ERR_NOMEM
- *     WIMLIB_ERR_INVALID_SECURITY_DATA
  */
 int
 read_wim_security_data(const u8 metadata_resource[], size_t metadata_resource_len,
@@ -271,10 +272,9 @@ read_wim_security_data(const u8 metadata_resource[], size_t metadata_resource_le
                total_len += sd->sizes[i];
                if (total_len > (u64)sd->total_length)
                        goto out_invalid_sd;
-               sd->descriptors[i] = MALLOC(sd->sizes[i]);
+               sd->descriptors[i] = memdup(p, sd->sizes[i]);
                if (!sd->descriptors[i])
                        goto out_of_memory;
-               memcpy(sd->descriptors[i], p, sd->sizes[i]);
                p += sd->sizes[i];
                empty_sacl_fixup((SECURITY_DESCRIPTOR_RELATIVE*)sd->descriptors[i],
                                 &sd->sizes[i]);
@@ -292,7 +292,7 @@ out_align_total_length:
        goto out;
 out_invalid_sd:
        ERROR("WIM security data is invalid!");
-       ret = WIMLIB_ERR_INVALID_SECURITY_DATA;
+       ret = WIMLIB_ERR_INVALID_METADATA_RESOURCE;
        goto out_free_sd;
 out_of_memory:
        ERROR("Out of memory while reading WIM security data!");
@@ -569,13 +569,12 @@ sd_set_add_sd(struct wim_sd_set *sd_set, const char *descriptor, size_t size)
        new = MALLOC(sizeof(*new));
        if (!new)
                goto out;
-       descr_copy = MALLOC(size);
+
+       descr_copy = memdup(descriptor, size);
        if (!descr_copy)
                goto out_free_node;
 
        sd = sd_set->sd;
-
-       memcpy(descr_copy, descriptor, size);
        new->security_id = sd->num_entries;
        copy_hash(new->hash, hash);