Fix use-after-free.
Found by clang static analyzer.
diff --git a/lib/zip_hash.c b/lib/zip_hash.c
index ec6e336..2918f69 100644
--- a/lib/zip_hash.c
+++ b/lib/zip_hash.c
@@ -245,13 +245,17 @@
entry = hash->table[i];
while (entry) {
if (entry->orig_index == -1) {
+ zip_hash_entry_t *p;
if (previous) {
previous->next = entry->next;
}
else {
hash->table[i] = entry->next;
}
- free(entry);
+ p = entry;
+ entry = entry->next;
+ free(p);
+ continue;
}
else {
entry->current_index = entry->orig_index;
diff --git a/lib/zip_source_win32a.c b/lib/zip_source_win32a.c
index ac1f256..a7cfacd 100644
--- a/lib/zip_source_win32a.c
+++ b/lib/zip_source_win32a.c
@@ -43,6 +43,15 @@
static int _win32_rename_temp_a(_zip_source_win32_read_file_t *ctx);
static int _win32_remove_a(const void *fname);
+#ifdef __BORLANDC__
+static _zip_source_win32_file_ops_t win32_ops_a = {
+ _win32_strdup_a,
+ _win32_open_a,
+ _win32_create_temp_a,
+ _win32_rename_temp_a,
+ _win32_remove_a
+};
+#else
static _zip_source_win32_file_ops_t win32_ops_a = {
.op_strdup = _win32_strdup_a,
.op_open = _win32_open_a,
@@ -50,6 +59,7 @@
.op_rename_temp = _win32_rename_temp_a,
.op_remove = _win32_remove_a
};
+#endif
ZIP_EXTERN zip_source_t *
zip_source_win32a(zip_t *za, const char *fname, zip_uint64_t start, zip_int64_t len)
diff --git a/lib/zip_source_win32w.c b/lib/zip_source_win32w.c
index cf0801e..754cd76 100644
--- a/lib/zip_source_win32w.c
+++ b/lib/zip_source_win32w.c
@@ -43,6 +43,15 @@
static int _win32_rename_temp_w(_zip_source_win32_read_file_t *ctx);
static int _win32_remove_w(const void *fname);
+#ifdef __BORLANDC__
+static _zip_source_win32_file_ops_t win32_ops_w = {
+ _win32_strdup_w,
+ _win32_open_w,
+ _win32_create_temp_w,
+ _win32_rename_temp_w,
+ _win32_remove_w
+};
+#else
static _zip_source_win32_file_ops_t win32_ops_w = {
.op_strdup = _win32_strdup_w,
.op_open = _win32_open_w,
@@ -50,6 +59,7 @@
.op_rename_temp = _win32_rename_temp_w,
.op_remove = _win32_remove_w
};
+#endif
ZIP_EXTERN zip_source_t *
zip_source_win32w(zip_t *za, const wchar_t *fname, zip_uint64_t start, zip_int64_t len)
diff --git a/lib/zipint.h b/lib/zipint.h
index c0242cc..2548da9 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -129,8 +129,6 @@
#define strcasecmp _stricmp
#elif defined(HAVE_STRICMP)
#define strcasecmp stricmp
-#else
-#error no case-insensitive string comparison operation found
#endif
#endif
diff --git a/regress/modify.c b/regress/modify.c
index 3fb8eda..3926460 100644
--- a/regress/modify.c
+++ b/regress/modify.c
@@ -40,7 +40,7 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#include <inttypes.h>
+#include <zipconf.h>
#ifdef _WIN32
/* WIN32 needs <fcntl.h> for _O_BINARY */
#include <fcntl.h>
@@ -51,6 +51,7 @@
#endif
#include "zip.h"
+#include "compat.h"
zip_source_t *source_hole_create(const char *, int flags, zip_error_t *);