From 7e59a8c5e4dcbc19170a54e8a26f77e7256ee29d Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 11 Mar 2009 04:03:14 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ ext/dl/handle.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7bcf57ff0a..9c6e789ff8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Mar 11 13:03:12 2009 Nobuyoshi Nakada + + * ext/dl/handle.c (rb_dlhandle_sym): fixed heap corruption. + [ruby-core:22822] + Wed Mar 11 06:12:47 2009 Nobuyoshi Nakada * ruby.c (ruby_init_loadpath_safe): expands libpath and removes diff --git a/ext/dl/handle.c b/ext/dl/handle.c index 474e97da3d..a65e4ab5cd 100644 --- a/ext/dl/handle.c +++ b/ext/dl/handle.c @@ -166,6 +166,7 @@ rb_dlhandle_sym(VALUE self, VALUE sym) func = dlsym(handle, name); CHECK_DLERROR; +#if defined(FUNC_STDCALL) if( !func ){ int len = strlen(name); char *name_n; @@ -173,14 +174,12 @@ rb_dlhandle_sym(VALUE self, VALUE sym) { char *name_a = (char*)xmalloc(len+2); strcpy(name_a, name); + name_n = name_a; name_a[len] = 'A'; name_a[len+1] = '\0'; func = dlsym(handle, name_a); CHECK_DLERROR; - if( func ){ - xfree(name_a); - goto found; - } + if( func ) goto found; name_n = xrealloc(name_a, len+6); } #else @@ -194,7 +193,6 @@ rb_dlhandle_sym(VALUE self, VALUE sym) CHECK_DLERROR; if( func ) break; } - xfree(name_n); if( func ) goto found; name_n[len-1] = 'A'; name_n[len++] = '@'; @@ -204,11 +202,13 @@ rb_dlhandle_sym(VALUE self, VALUE sym) CHECK_DLERROR; if( func ) break; } - if( !func ){ - rb_raise(rb_eDLError, "unknown symbol \"%s\"", name); - } + found: + xfree(name_n); + } +#endif + if( !func ){ + rb_raise(rb_eDLError, "unknown symbol \"%s\"", name); } - found: return PTR2NUM(func); }