From 46e06b572bca7e7e483a26750c59d8f85de5a2f8 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 2 Mar 2009 01:50:56 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ ext/dl/handle.c | 55 ++++++++++++++++++++++--------------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8dea93edbb..969666ce9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Mar 2 10:50:53 2009 Nobuyoshi Nakada + + * ext/dl/handle.c (rb_dlhandle_sym): get rid of buffer overrun, + and try ASCII WINAPI versions too. + Mon Mar 2 10:29:17 2009 Nobuyoshi Nakada * eval.c (rb_longjmp), include/ruby/intern.h (ruby_cleanup): fixed 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); }