[前][次][番号順一覧][スレッド一覧]

ruby-changes:11154

From: yugui <ko1@a...>
Date: Wed, 4 Mar 2009 18:21:17 +0900 (JST)
Subject: [ruby-changes:11154] Ruby:r22759 (ruby_1_9_1): merges r22702 from trunk into ruby_1_9_1.

yugui	2009-03-04 18:21:04 +0900 (Wed, 04 Mar 2009)

  New Revision: 22759

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22759

  Log:
    merges r22702 from trunk into ruby_1_9_1.
    --
    * ext/dl/handle.c (rb_dlhandle_sym): get rid of buffer overrun,
      and try ASCII WINAPI versions too.

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/ext/dl/handle.c

Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 22758)
+++ ruby_1_9_1/ChangeLog	(revision 22759)
@@ -1,3 +1,8 @@
+Mon Mar  2 10:50:53 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/dl/handle.c (rb_dlhandle_sym): get rid of buffer overrun,
+	  and try ASCII WINAPI versions too.
+
 Mon Mar  2 00:56:45 2009  Masatoshi SEKI  <m_seki@m...>
 
 	* lib/drb/observer.rb: The module oberservable uses now a hash to
Index: ruby_1_9_1/ext/dl/handle.c
===================================================================
--- ruby_1_9_1/ext/dl/handle.c	(revision 22758)
+++ ruby_1_9_1/ext/dl/handle.c	(revision 22759)
@@ -161,53 +161,48 @@
     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);
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]