Add precheck program to test whether LD_PRELOAD works for calls within libzip.
diff --git a/developer-xcode/libzip.xcodeproj/project.pbxproj b/developer-xcode/libzip.xcodeproj/project.pbxproj
index 8e7d23b..a4c2ed6 100644
--- a/developer-xcode/libzip.xcodeproj/project.pbxproj
+++ b/developer-xcode/libzip.xcodeproj/project.pbxproj
@@ -604,6 +604,9 @@
4B28AA2515BAD4E200D0C17D /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
4B28AA2615BAD4E200D0C17D /* THANKS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = THANKS; sourceTree = "<group>"; };
4B28AA2715BAD4E200D0C17D /* TODO.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = TODO.md; sourceTree = "<group>"; };
+ 4B30B4BF25F0ECC8002CE070 /* liboverride.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = liboverride.c; sourceTree = "<group>"; };
+ 4B30B4D025F0ECF7002CE070 /* fuzz_main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = fuzz_main.c; sourceTree = "<group>"; };
+ 4B30B4D125F0EE6D002CE070 /* liboverride-test.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "liboverride-test.c"; sourceTree = "<group>"; };
4B3A5F4D1DF96D83005A53A1 /* zip_fseek.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_fseek.c; sourceTree = "<group>"; };
4B3A5F4E1DF96D83005A53A1 /* zip_ftell.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_ftell.c; sourceTree = "<group>"; };
4B3FAE7F2385C5A300192D6A /* zip_algorithm_xz.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip_algorithm_xz.c; sourceTree = "<group>"; };
@@ -1202,7 +1205,10 @@
4BACD57A15BC2AEF00920691 /* fopen_unchanged.c */,
4BACD57B15BC2AEF00920691 /* fread.c */,
4BC03F9A1FDD5617003C7B62 /* fseek.c */,
+ 4B30B4D025F0ECF7002CE070 /* fuzz_main.c */,
4BD6CB5E19E71B3B00710654 /* hole.c */,
+ 4B30B4BF25F0ECC8002CE070 /* liboverride.c */,
+ 4B30B4D125F0EE6D002CE070 /* liboverride-test.c */,
4BC03F9C1FDD5617003C7B62 /* malloc.c */,
4B4CB5572483D7B7005C5428 /* nihtest.conf.in */,
4BD155CE191CD28D0046F012 /* NiHTest.pm */,
diff --git a/regress/CMakeLists.txt b/regress/CMakeLists.txt
index 3f5b543..b24c813 100644
--- a/regress/CMakeLists.txt
+++ b/regress/CMakeLists.txt
@@ -7,6 +7,7 @@
fseek
fuzz_main
nonrandomopentest
+ liboverride-test
)
set(GETOPT_USERS
@@ -45,6 +46,7 @@
set(DL_USERS
# malloc
nonrandomopen
+ liboverride
)
foreach(PROGRAM IN LISTS DL_USERS)
diff --git a/regress/liboverride-test.c b/regress/liboverride-test.c
new file mode 100644
index 0000000..c274f61
--- /dev/null
+++ b/regress/liboverride-test.c
@@ -0,0 +1,83 @@
+/*
+ liboverride.c -- override function called by zip_open()
+
+ Copyright (C) 2017-2020 Dieter Baron and Thomas Klausner
+
+ This file is part of ckmame, a program to check rom sets for MAME.
+ The authors can be contacted at <ckmame@nih.at>
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "zip.h"
+
+#define DEBUG 1
+
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
+/*
+ Some systems bind functions called and defined within a shared library, so the override doesn't work. This program calls zip_open and checks whether the override worked.
+ */
+
+int
+main(int argc, const char *argv[]) {
+ int error_code;
+
+ if (getenv("LIBOVERRIDE_SET") == NULL) {
+ setenv("LIBOVERRIDE_SET", "1", 1);
+ setenv("LD_PRELOAD", "libliboverride.so", 1);
+#ifdef DEBUG
+ printf("setting LD_PRELOAD and calling us again\n");
+#endif
+ execv(argv[0], (void *)argv);
+ exit(2);
+ }
+
+ if (zip_open("nosuchfile", 0, &error_code) != NULL) {
+#ifdef DEBUG
+ printf("zip_open() succeeded\n");
+#endif
+ /* We expect failure. */
+ exit(1);
+ }
+ if (error_code != 32000) {
+#ifdef DEBUG
+ printf("got wrong error code %d\n", error_code);
+#endif
+ /* Override didn't take, we didn't get its magic error code. */
+ exit(1);
+ }
+
+#ifdef DEBUG
+ printf("override worked\n");
+#endif
+ exit(0);
+}
diff --git a/regress/liboverride.c b/regress/liboverride.c
new file mode 100644
index 0000000..b2a6530
--- /dev/null
+++ b/regress/liboverride.c
@@ -0,0 +1,48 @@
+/*
+ liboverride.c -- override function called by zip_open()
+
+ Copyright (C) 2017-2020 Dieter Baron and Thomas Klausner
+
+ This file is part of ckmame, a program to check rom sets for MAME.
+ The authors can be contacted at <ckmame@nih.at>
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "zipint.h"
+
+/*
+ Some systems bind functions called and defined within a shared library, so the override doesn't work. This overrides a function called by zip_open to return an invalid error code so we can check whether the override works.
+ */
+
+zip_source_t *
+zip_source_file_create(const char *fname, zip_uint64_t start, zip_int64_t length, zip_error_t *error) {
+ if (error != NULL) {
+ error->zip_err = 32000;
+ }
+
+ return NULL;
+}