diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-07 01:23:27 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-07 01:23:27 +0000 |
commit | 2f2925c4df7051370e177c83507eba7413f653f5 (patch) | |
tree | 2b74e5c13b69ea0fdedd271be1f6c29b179c905a /ext/socket | |
parent | caaec1e02cc178ff833bf137f6576ff01b74b53f (diff) | |
download | ruby-2f2925c4df7051370e177c83507eba7413f653f5.tar.gz ruby-2f2925c4df7051370e177c83507eba7413f653f5.tar.xz ruby-2f2925c4df7051370e177c83507eba7413f653f5.zip |
* ext/socket/socket.c (make_hostent): get rid of SEGV on aliases
lookup failure. (ruby-bugs:PR#1215)
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/socket.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c index aa568cf6b..e30d25404 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)); |