[eglib] In AIX/generic POSIX, handle null addresses better (mono/mono#17892)
authorCalvin Buckley <calvin@cmpct.info>
Mon, 25 Nov 2019 07:52:54 +0000 (03:52 -0400)
committerRyan Lucia <rylucia@microsoft.com>
Mon, 25 Nov 2019 07:52:54 +0000 (02:52 -0500)
Fixes crash in tests on AIX.

Matches mono/mono@b0d966bd7ab887f075f6ce3d1c9858af6b52f30f

Commit migrated from https://github.com/mono/mono/commit/004fd06b967e0d2fd0e28bc516e8e33fe8a75a21

src/mono/mono/eglib/gmodule-aix.c
src/mono/mono/eglib/gmodule-unix.c

index ab270e3..3af4708 100644 (file)
@@ -219,12 +219,20 @@ g_module_address (void *addr, char *file_name, size_t file_name_len,
        /* This zero-on-failure is unlike other Unix APIs. */
        if (ret == 0)
                return FALSE;
-       if (file_name != NULL && file_name_len >= 1)
-               g_strlcpy(file_name, dli.dli_fname, file_name_len);
+       if (file_name != NULL && file_name_len >= 1) {
+               if (dli.dli_fname != NULL)
+                       g_strlcpy(file_name, dli.dli_fname, file_name_len);
+               else
+                       file_name [0] = '\0';
+       }
        if (file_base != NULL)
                *file_base = dli.dli_fbase;
-       if (sym_name != NULL && sym_name_len >= 1)
-               g_strlcpy(sym_name, dli.dli_sname, sym_name_len);
+       if (sym_name != NULL && sym_name_len >= 1) {
+               if (dli.dli_sname != NULL)
+                       g_strlcpy(sym_name, dli.dli_sname, sym_name_len);
+               else
+                       sym_name [0] = '\0';
+       }
        if (sym_addr != NULL)
                *sym_addr = dli.dli_saddr;
        return TRUE;
index 3f60af2..24b3a30 100644 (file)
@@ -94,8 +94,12 @@ g_module_address (void *addr, char *file_name, size_t file_name_len,
        /*
         * AIX/Win32 return non-const, so we use caller-allocated bufs instead
         */
-       if (file_name != NULL && file_name_len >= 1)
-               g_strlcpy(file_name, dli.dli_fname, file_name_len);
+       if (file_name != NULL && file_name_len >= 1) {
+               if (dli.dli_fname)
+                       g_strlcpy(file_name, dli.dli_fname, file_name_len);
+               else
+                       file_name [0] = '\0';
+       }
        if (file_base != NULL)
                *file_base = dli.dli_fbase;
        if (sym_name != NULL && sym_name_len >= 1) {