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

ruby-changes:11104

From: nobu <ko1@a...>
Date: Mon, 2 Mar 2009 10:51:07 +0900 (JST)
Subject: [ruby-changes:11104] Ruby:r22702 (trunk): * ext/dl/handle.c (rb_dlhandle_sym): get rid of buffer overrun,

nobu	2009-03-02 10:50:56 +0900 (Mon, 02 Mar 2009)

  New Revision: 22702

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

  Log:
    * ext/dl/handle.c (rb_dlhandle_sym): get rid of buffer overrun,
      and try ASCII WINAPI versions too.

  Modified files:
    trunk/ChangeLog
    trunk/ext/dl/handle.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 22701)
+++ ChangeLog	(revision 22702)
@@ -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 10:29:17 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* eval.c (rb_longjmp), include/ruby/intern.h (ruby_cleanup): fixed
Index: ext/dl/handle.c
===================================================================
--- ext/dl/handle.c	(revision 22701)
+++ ext/dl/handle.c	(revision 22702)
@@ -160,53 +160,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/

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