1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/dl/handle.c (rb_dlhandle_sym): fixed heap corruption.

[ruby-core:22822]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-03-11 04:03:14 +00:00
parent 745bc1fd83
commit 7e59a8c5e4
2 changed files with 14 additions and 9 deletions

View file

@ -1,3 +1,8 @@
Wed Mar 11 13:03:12 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/dl/handle.c (rb_dlhandle_sym): fixed heap corruption.
[ruby-core:22822]
Wed Mar 11 06:12:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Mar 11 06:12:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (ruby_init_loadpath_safe): expands libpath and removes * ruby.c (ruby_init_loadpath_safe): expands libpath and removes

View file

@ -166,6 +166,7 @@ rb_dlhandle_sym(VALUE self, VALUE sym)
func = dlsym(handle, name); func = dlsym(handle, name);
CHECK_DLERROR; CHECK_DLERROR;
#if defined(FUNC_STDCALL)
if( !func ){ if( !func ){
int len = strlen(name); int len = strlen(name);
char *name_n; char *name_n;
@ -173,14 +174,12 @@ rb_dlhandle_sym(VALUE self, VALUE sym)
{ {
char *name_a = (char*)xmalloc(len+2); char *name_a = (char*)xmalloc(len+2);
strcpy(name_a, name); strcpy(name_a, name);
name_n = name_a;
name_a[len] = 'A'; name_a[len] = 'A';
name_a[len+1] = '\0'; name_a[len+1] = '\0';
func = dlsym(handle, name_a); func = dlsym(handle, name_a);
CHECK_DLERROR; CHECK_DLERROR;
if( func ){ if( func ) goto found;
xfree(name_a);
goto found;
}
name_n = xrealloc(name_a, len+6); name_n = xrealloc(name_a, len+6);
} }
#else #else
@ -194,7 +193,6 @@ rb_dlhandle_sym(VALUE self, VALUE sym)
CHECK_DLERROR; CHECK_DLERROR;
if( func ) break; if( func ) break;
} }
xfree(name_n);
if( func ) goto found; if( func ) goto found;
name_n[len-1] = 'A'; name_n[len-1] = 'A';
name_n[len++] = '@'; name_n[len++] = '@';
@ -204,11 +202,13 @@ rb_dlhandle_sym(VALUE self, VALUE sym)
CHECK_DLERROR; CHECK_DLERROR;
if( func ) break; if( func ) break;
} }
if( !func ){ found:
rb_raise(rb_eDLError, "unknown symbol \"%s\"", name); xfree(name_n);
} }
#endif
if( !func ){
rb_raise(rb_eDLError, "unknown symbol \"%s\"", name);
} }
found:
return PTR2NUM(func); return PTR2NUM(func);
} }