From a51b5fa52bb66cb443f1084f0764287e7e5afa4e Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 7 Nov 2003 01:23:27 +0000 Subject: * ext/socket/socket.c (make_hostent): get rid of SEGV on aliases lookup failure. (ruby-bugs:PR#1215) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/socket.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'ext/socket') diff --git a/ext/socket/socket.c b/ext/socket/socket.c index aa568cf6b3..e30d25404d 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -1033,8 +1033,6 @@ make_hostent(addr, ipaddr) ary = rb_ary_new(); rb_ary_push(ary, rb_str_new2(addr->ai_canonname)); - names = rb_ary_new(); - rb_ary_push(ary, names); #if defined(HAVE_GETIPNODEBYNAME) { int error; @@ -1046,14 +1044,21 @@ make_hostent(addr, ipaddr) #else h = gethostbyname(addr->ai_canonname); #endif - if (h->h_aliases != NULL) { - for (pch = h->h_aliases; *pch; pch++) { - rb_ary_push(names, rb_str_new2(*pch)); + if (h) { + names = rb_ary_new(); + if (h->h_aliases != NULL) { + for (pch = h->h_aliases; *pch; pch++) { + rb_ary_push(names, rb_str_new2(*pch)); + } } - } #if defined(HAVE_GETIPNODEBYNAME) - freehostent(h); + freehostent(h); #endif + } + else { + names = rb_ary_new2(0); + } + rb_ary_push(ary, names); rb_ary_push(ary, INT2NUM(addr->ai_family)); for (ai = addr; ai; ai = ai->ai_next) { rb_ary_push(ary, (*ipaddr)(ai->ai_addr, ai->ai_addrlen)); -- cgit v1.2.3