PR_GetLibraryFilePathname with NULL name argument crashes on Mac

NEW
Assigned to

Status

NSPR
NSPR
8 years ago
8 years ago

People

(Reporter: Meena Vyas, Assigned: Wan-Teh Chang)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11) Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11
Build Identifier: 4.7.5

Installed nss nspr using
$sudo /opt/local/bin/port install nss

 char *name = PR_GetLibraryFilePathname(NULL, (PRFuncPtr)_dll_library);
works fine on all platforms but on MAC as NULL is passed to strstr.

http://src.opensolaris.org/source/xref/webstack/webserver/src/server/base/dll.cpp#74 
Web Server is calling PR_GetLibraryFilePathname with first argument as NULL.  I get Bus error.

debugger shows stack :

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x969bf7f3 in strstr ()
(gdb) where
#0  0x969bf7f3 in strstr ()
#1  0x000f6345 in PR_GetLibraryFilePathname ()
#2  0x00402fa1 in DllInitialize::DllInitialize (this=0x64dd50) at   dll.cpp:79
#3  0x005b1422 in __static_initialization_and_destruction_0
    (__initialize_p=1, __priority=65535) at dll.cpp:101
#4  0x005b143d in global constructors keyed to _dll_initialize () at
    dll.cpp:222
#5  0x8fe12f36 in    __dyld__ZN16ImageLoaderMachO18doModInitFunctionsERKN11ImageLoader11LinkContextE
    ()
#6  0x8fe0e7e3 in
   __dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEj ()
#7  0x8fe0e775 in __dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEj ()
#8  0x8fe0e8c9 in    __dyld__ZN11ImageLoader15runInitializersERKNS_11LinkContextE ()
#9  0x8fe04102 in __dyld__ZN4dyld24initializeMainExecutableEv ()
#10 0x8fe07bcf in __dyld__ZN4dyld5_mainEPK11mach_headermiPPKcS5_S5_ ()
#11 0x8fe01872 in __dyld__ZN13dyldbootstrap5startEPK11mach_headeriPPKcl ()
#12 0x8fe01037 in __dyld__dyld_start ()

Reason : 
  "mozilla/nsprpub/pr/src/linking/prlink.c"
...
    PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr)
    {
    #if defined(USE_DLFCN) && (defined(SOLARIS) || defined(FREEBSD) \
            || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__))
    ...
    #elif defined(USE_MACH_DYLD)
        char *result;
        const char *image_name;
        int i, count = _dyld_image_count();

        for (i = 0; i < count; i++) {
            image_name = _dyld_get_image_name(i);
            if (strstr(image_name, name) != NULL) {
                result = PR_Malloc(strlen(image_name)+1);
                if (result != NULL) {
                    strcpy(result, image_name);
                }
                return result;

Reproducible: Always
How did you encounter this, Meena?
Is there a Sun CR for it?
Summary: Bus error on Mac when PR_GetLibraryFilePathname is getting called with NULL as the first argument → PR_GetLibraryFilePathname with NULL name argument crashes on Mac
(Assignee)

Comment 2

8 years ago
The best we can do is to make PR_GetLibraryFilePathname fail
with the PR_INVALID_ARGUMENT_ERROR.  You still need to pass
the library name as the 'name' argument to PR_GetLibraryFilePathname.
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Reporter)

Comment 3

8 years ago
>How did you encounter this
While writing my blog http://blogs.sun.com/meena/entry/running_open_web_server_on
>Is there a Sun CR for it?
No. Should I file one?
You need to log in before you can comment on or make changes to this bug.