diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-02 01:50:56 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-02 01:50:56 +0000 |
commit | 46e06b572bca7e7e483a26750c59d8f85de5a2f8 (patch) | |
tree | 194f7b4201d024600479cca93c352dda5a91f1ff /ext/dl/handle.c | |
parent | 9fb56049eb62bdc5953a2cd66e472a23cd20070b (diff) | |
download | ruby-46e06b572bca7e7e483a26750c59d8f85de5a2f8.tar.gz |
* ext/dl/handle.c (rb_dlhandle_sym): get rid of buffer overrun,
and try ASCII WINAPI versions too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/handle.c')
-rw-r--r-- | ext/dl/handle.c | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/ext/dl/handle.c b/ext/dl/handle.c index b727f46763..b8752004bc 100644 --- a/ext/dl/handle.c +++ b/ext/dl/handle.c @@ -160,53 +160,48 @@ rb_dlhandle_sym(VALUE self, VALUE sym) func = dlsym(handle, name); CHECK_DLERROR; if( !func ){ -#if defined(__CYGWIN__) || defined(WIN32) || defined(__MINGW32__) + int len = strlen(name); + char *name_n; +#if defined(__CYGWIN__) || defined(_WIN32) || defined(__MINGW32__) { - int len = strlen(name); char *name_a = (char*)xmalloc(len+2); strcpy(name_a, name); name_a[len] = 'A'; name_a[len+1] = '\0'; func = dlsym(handle, name_a); - xfree(name_a); CHECK_DLERROR; - if( !func ){ - for( i = 0; i < 256; i += 4 ){ - int len = strlen(name); - char *name_n = (char*)xmalloc(len+5); - sprintf(name_n, "%s@%d%c", name, i, 0); - func = dlsym(handle, name_n); - xfree(name_n); - CHECK_DLERROR; - if( func ) - { - break; - } - } - CHECK_DLERROR; - if( !func ){ - rb_raise(rb_eDLError, "unknown symbol \"%s\"", name); - } + if( func ){ + xfree(name_a); + goto found; } + name_n = xrealloc(name_a, len+6); } #else + name_n = (char*)xmalloc(len+6); +#endif + memcpy(name_n, name, len); + name_n[len++] = '@'; for( i = 0; i < 256; i += 4 ){ - int len = strlen(name); - char *name_n = (char*)xmalloc(len+4); - sprintf(name_n, "%s@%d", name, i); + sprintf(name_n + len, "%d", i); func = dlsym(handle, name_n); - xfree(name_n); CHECK_DLERROR; - if( func ){ - break; - } + if( func ) break; } - CHECK_DLERROR; - if( !func ){ + xfree(name_n); + if( func ) goto found; + name_n[len-1] = 'A'; + name_n[len++] = '@'; + for( i = 0; i < 256; i += 4 ){ + sprintf(name_n + len, "%d", i); + func = dlsym(handle, name_n); + CHECK_DLERROR; + if( func ) break; + } + if( !func ){ rb_raise(rb_eDLError, "unknown symbol \"%s\"", name); } -#endif } + found: return PTR2NUM(func); } |