Don't assume to know the shared library extension
authorRichard Levitte <levitte@openssl.org>
Thu, 3 Nov 2016 17:48:23 +0000 (18:48 +0100)
committerRichard Levitte <levitte@openssl.org>
Thu, 3 Nov 2016 23:19:14 +0000 (00:19 +0100)
test/shlibloadtest.c assumes all Unix style platforms use .so as
shared library extension.  This is not the case for Mac OS X, which
uses .dylib.  Instead of this, have the test recipe find out the
extension from configuration data.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1844)

test/recipes/90-test_shlibload.t
test/shlibloadtest.c

index dc35613..9058ba5 100644 (file)
@@ -22,16 +22,15 @@ plan skip_all => "Test only supported in a shared build" if disabled("shared");
 
 plan tests => 3;
 
-ok(run(test(["shlibloadtest", "-crypto_first",
-             $unified_info{sharednames}->{libcrypto},
-             $unified_info{sharednames}->{libssl}])),
+my $libcrypto =
+    $unified_info{sharednames}->{libcrypto}.$target{shared_extension_simple};
+my $libssl =
+    $unified_info{sharednames}->{libssl}.$target{shared_extension_simple};
+
+ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl])),
    "running shlibloadtest -crypto_first");
-ok(run(test(["shlibloadtest", "-ssl_first",
-             $unified_info{sharednames}->{libcrypto},
-             $unified_info{sharednames}->{libssl}])),
+ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl])),
    "running shlibloadtest -ssl_first");
-ok(run(test(["shlibloadtest", "-just_crypto",
-             $unified_info{sharednames}->{libcrypto},
-             $unified_info{sharednames}->{libssl}])),
+ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl])),
    "running shlibloadtest -just_crypto");
 
index 20030d9..eea2e3a 100644 (file)
@@ -44,22 +44,9 @@ typedef void * SHLIB;
 typedef void * SHLIB_SYM;
 # define SHLIB_INIT NULL
 
-# define SHARED_LIBRARY_SUFFIX ".so"
-
-static int shlib_load(char *filename, SHLIB *lib)
+static int shlib_load(const char *filename, SHLIB *lib)
 {
-    char *tmpfile;
-    size_t filenamelen = strlen(filename);
-
-    /* Total length = base filename len + suffix len + 1 for NULL terminator */
-    tmpfile = malloc(filenamelen + sizeof(SHARED_LIBRARY_SUFFIX) + 1);
-    if (tmpfile == NULL)
-        return 0;
-    strcpy(tmpfile, filename);
-    strcpy(tmpfile + filenamelen, SHARED_LIBRARY_SUFFIX);
-
-    *lib = dlopen(tmpfile, RTLD_GLOBAL | RTLD_LAZY);
-    free(tmpfile);
+    *lib = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
 
     if (*lib == NULL)
         return 0;
@@ -90,7 +77,7 @@ typedef HINSTANCE SHLIB;
 typedef void * SHLIB_SYM;
 # define SHLIB_INIT 0
 
-static int shlib_load(char *filename, SHLIB *lib)
+static int shlib_load(const char *filename, SHLIB *lib)
 {
     *lib = LoadLibraryA(filename);
     if (*lib == NULL)