GH614: Use memcpy()/strdup() when possible
[openssl.git] / crypto / dso / dso_win32.c
index bd96c5d2e3e62ea4779f560da9a96591869a66eb..3d9ee8a5580fe562d5a2187af006535b2db5b496 100644 (file)
@@ -1,4 +1,3 @@
-/* dso_win32.c -*- mode:C; c-file-style: "eay" -*- */
 /*
  * Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project
  * 2000.
@@ -59,7 +58,7 @@
 
 #include <stdio.h>
 #include <string.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include <openssl/dso.h>
 
 #if !defined(DSO_WIN32)
@@ -224,7 +223,10 @@ static int win32_unload(DSO *dso)
 static void *win32_bind_var(DSO *dso, const char *symname)
 {
     HINSTANCE *ptr;
-    void *sym;
+    union {
+        void *p;
+        FARPROC f;
+    } sym;
 
     if ((dso == NULL) || (symname == NULL)) {
         DSOerr(DSO_F_WIN32_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER);
@@ -239,19 +241,22 @@ static void *win32_bind_var(DSO *dso, const char *symname)
         DSOerr(DSO_F_WIN32_BIND_VAR, DSO_R_NULL_HANDLE);
         return (NULL);
     }
-    sym = GetProcAddress(*ptr, symname);
-    if (sym == NULL) {
+    sym.f = GetProcAddress(*ptr, symname);
+    if (sym.p == NULL) {
         DSOerr(DSO_F_WIN32_BIND_VAR, DSO_R_SYM_FAILURE);
         ERR_add_error_data(3, "symname(", symname, ")");
         return (NULL);
     }
-    return (sym);
+    return (sym.p);
 }
 
 static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
 {
     HINSTANCE *ptr;
-    void *sym;
+    union {
+        void *p;
+        FARPROC f;
+    } sym;
 
     if ((dso == NULL) || (symname == NULL)) {
         DSOerr(DSO_F_WIN32_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER);
@@ -266,13 +271,13 @@ static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
         DSOerr(DSO_F_WIN32_BIND_FUNC, DSO_R_NULL_HANDLE);
         return (NULL);
     }
-    sym = GetProcAddress(*ptr, symname);
-    if (sym == NULL) {
+    sym.f = GetProcAddress(*ptr, symname);
+    if (sym.p == NULL) {
         DSOerr(DSO_F_WIN32_BIND_FUNC, DSO_R_SYM_FAILURE);
         ERR_add_error_data(3, "symname(", symname, ")");
         return (NULL);
     }
-    return ((DSO_FUNC_TYPE)sym);
+    return ((DSO_FUNC_TYPE)sym.f);
 }
 
 struct file_st {
@@ -304,13 +309,12 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
         return (NULL);
     }
 
-    result = OPENSSL_malloc(sizeof(*result));
+    result = OPENSSL_zalloc(sizeof(*result));
     if (result == NULL) {
         DSOerr(DSO_F_WIN32_SPLITTER, ERR_R_MALLOC_FAILURE);
         return (NULL);
     }
 
-    memset(result, 0, sizeof(struct file_st));
     position = IN_DEVICE;
 
     if ((filename[0] == '\\' && filename[1] == '\\')
@@ -428,7 +432,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split)
     }
 
     result = OPENSSL_malloc(len + 1);
-    if (!result) {
+    if (result == NULL) {
         DSOerr(DSO_F_WIN32_JOINER, ERR_R_MALLOC_FAILURE);
         return (NULL);
     }
@@ -494,14 +498,14 @@ static char *win32_merger(DSO *dso, const char *filespec1,
     }
     if (!filespec2) {
         merged = OPENSSL_malloc(strlen(filespec1) + 1);
-        if (!merged) {
+        if (merged == NULL) {
             DSOerr(DSO_F_WIN32_MERGER, ERR_R_MALLOC_FAILURE);
             return (NULL);
         }
         strcpy(merged, filespec1);
     } else if (!filespec1) {
         merged = OPENSSL_malloc(strlen(filespec2) + 1);
-        if (!merged) {
+        if (merged == NULL) {
             DSOerr(DSO_F_WIN32_MERGER, ERR_R_MALLOC_FAILURE);
             return (NULL);
         }
@@ -705,7 +709,10 @@ static void *win32_globallookup(const char *name)
     CREATETOOLHELP32SNAPSHOT create_snap;
     CLOSETOOLHELP32SNAPSHOT close_snap;
     MODULE32 module_first, module_next;
-    FARPROC ret = NULL;
+    union {
+        void *p;
+        FARPROC f;
+    } ret = { NULL };
 
     dll = LoadLibrary(TEXT(DLLNAME));
     if (dll == NULL) {
@@ -746,10 +753,10 @@ static void *win32_globallookup(const char *name)
     }
 
     do {
-        if ((ret = GetProcAddress(me32.hModule, name))) {
+        if ((ret.f = GetProcAddress(me32.hModule, name))) {
             (*close_snap) (hModuleSnap);
             FreeLibrary(dll);
-            return ret;
+            return ret.p;
         }
     } while ((*module_next) (hModuleSnap, &me32));