]> wimlib.net Git - wimlib/blobdiff - src/security.c
Code to handle some weird siutations and bad WIMs
[wimlib] / src / security.c
index 9707bd313359383f4b8a6c9bd4f81e0fe11eedeb..bc44b45ae9d3707dea3fe6fb670e47d5c3d326f6 100644 (file)
@@ -28,8 +28,6 @@
 #include "io.h"
 #include "security.h"
 
-#ifdef ENABLE_SECURITY_DATA
-
 /* 
  * Reads the security data from the metadata resource.
  *
@@ -127,6 +125,8 @@ int read_security_data(const u8 metadata_resource[], u64 metadata_resource_len,
                              "(current total length = %"PRIu64", security "
                              "descriptor size = %"PRIu64")",
                              total_len, sd->sizes[i]);
+                       ret = WIMLIB_ERR_INVALID_SECURITY_DATA;
+                       goto out_free_sd;
                }
                total_len += sd->sizes[i];
                if (total_len > (u64)sd->total_length) {
@@ -267,8 +267,8 @@ void free_security_data(struct wim_security_data *sd)
 {
        if (!sd)
                return;
-       wimlib_assert(sd->refcnt >= 1);
-       if (sd->refcnt == 1) {
+       wimlib_assert(sd->refcnt != 0);
+       if (--sd->refcnt == 0) {
                u8 **descriptors = sd->descriptors;
                u32 num_entries  = sd->num_entries;
                if (descriptors)
@@ -277,9 +277,5 @@ void free_security_data(struct wim_security_data *sd)
                FREE(sd->sizes);
                FREE(sd->descriptors);
                FREE(sd);
-       } else {
-               sd->refcnt--;
        }
 }
-
-#endif