From ece972717b2e752532b222f03500f23b03280327 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 24 Mar 2003 09:38:37 +0000 Subject: security enhancement of dl library (need test). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dl/sym.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ext/dl/sym.c') diff --git a/ext/dl/sym.c b/ext/dl/sym.c index 7e18e61b5e..2034c0a7ff 100644 --- a/ext/dl/sym.c +++ b/ext/dl/sym.c @@ -330,7 +330,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) long ftype; void *func; - rb_secure(4); + rb_secure(2); Data_Get_Struct(self, struct sym_data, sym); DEBUG_CODE({ printf("rb_dlsym_call(): type = '%s', func = 0x%x\n", sym->type, sym->func); @@ -457,20 +457,20 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self) ANY2S(args[i]) = DLSTR(0); } else{ - if( TYPE(argv[i]) != T_STRING ){ - rb_raise(rb_eDLError, "#%d must be a string",i); - } - ANY2S(args[i]) = DLSTR(RSTRING(argv[i])->ptr); + VALUE str = argv[i]; + SafeStringValue(str); + ANY2S(args[i]) = DLSTR(RSTRING(str)->ptr); } PUSH_P(ftype); break; case 's': - if( TYPE(argv[i]) != T_STRING ){ - rb_raise(rb_eDLError, "#%d must be a string",i); + { + VALUE str = argv[i]; + SafeStringValue(str); + ANY2S(args[i]) = DLSTR(dlmalloc(RSTRING(str)->len + 1)); + memcpy((char*)(ANY2S(args[i])), RSTRING(str)->ptr, RSTRING(str)->len + 1); + dtypes[i] = 's'; } - ANY2S(args[i]) = DLSTR(dlmalloc(RSTRING(argv[i])->len + 1)); - memcpy((char*)(ANY2S(args[i])), RSTRING(argv[i])->ptr, RSTRING(argv[i])->len + 1); - dtypes[i] = 's'; PUSH_P(ftype); break; default: -- cgit v1.2.3