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 | a51b5fa52bb66cb443f1084f0764287e7e5afa4e (patch) | |
tree | 2b74e5c13b69ea0fdedd271be1f6c29b179c905a /ext | |
parent | cac6465677edf7e8762b6e16ae40d0f091191aa3 (diff) |
* 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
Diffstat (limited to 'ext')
-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 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)); |