From: Adam Dickmeiss Date: Wed, 30 Aug 2006 12:04:42 +0000 (+0000) Subject: Fixed bug #644: Using Non Reentrant gethostbyname causes SIGSEGV. Function X-Git-Tag: YAZ.2.1.28~15 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=8a0937d20238aa0f26e564f7eacc0483acb102da;p=yaz-moved-to-github.git Fixed bug #644: Using Non Reentrant gethostbyname causes SIGSEGV. Function gethostbyname_r is used instead of gethostbyname - when available. --- diff --git a/NEWS b/NEWS index dced8d3..49a9dac 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +Fixed bug #644: Using Non Reentrant gethostbyname causes SIGSEGV. + New option for yaz-marcdump -lpos=value which allows setting a portion of MARC header to a certain value. diff --git a/configure.ac b/configure.ac index 758f4dd..53257da 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2006 dnl See the file LICENSE for details. -dnl $Id: configure.ac,v 1.32 2006-08-16 22:50:06 adam Exp $ +dnl $Id: configure.ac,v 1.33 2006-08-30 12:04:42 adam Exp $ AC_PREREQ(2.59) AC_INIT([yaz],[2.1.27],[adam@indexdata.dk]) AC_CONFIG_SRCDIR(configure.ac) @@ -164,7 +164,7 @@ if test "$with_iconv" != "no"; then ]) fi dnl ------ various functions -AC_CHECK_FUNCS(vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64) +AC_CHECK_FUNCS(gethostbyname_r vsnprintf gettimeofday poll strerror_r localtime_r usleep fopen64) case $host in *-*-darwin*) trypoll="no"; diff --git a/src/tcpip.c b/src/tcpip.c index a55d67c..5168c77 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tcpip.c,v 1.19 2006-08-24 13:25:45 adam Exp $ + * $Id: tcpip.c,v 1.20 2006-08-30 12:04:43 adam Exp $ */ /** * \file tcpip.c @@ -241,9 +241,14 @@ int tcpip_strtoaddr_ex(const char *str, struct sockaddr_in *add, int default_port) { struct hostent *hp; +#if HAVE_GETHOSTBYNAME_R + struct hostent h; + char hbuf[1024]; + int h_error; +#endif char *p, buf[512]; short int port = default_port; - unsigned tmpadd; + in_addr_t tmpadd; if (!tcpip_init ()) return 0; @@ -260,12 +265,26 @@ int tcpip_strtoaddr_ex(const char *str, struct sockaddr_in *add, } add->sin_port = htons(port); if (!strcmp("@", buf)) + { add->sin_addr.s_addr = INADDR_ANY; + } + else if ((tmpadd = inet_addr(buf)) != INADDR_NONE) + { + memcpy(&add->sin_addr.s_addr, &tmpadd, sizeof(struct in_addr)); + } +#if HAVE_GETHOSTBYNAME_R + else if (gethostbyname_r(buf, &h, hbuf, sizeof(hbuf), &hp, &h_error) == 0) + { + memcpy(&add->sin_addr.s_addr, *hp->h_addr_list, + sizeof(struct in_addr)); + } +#else else if ((hp = gethostbyname(buf))) + { memcpy(&add->sin_addr.s_addr, *hp->h_addr_list, sizeof(struct in_addr)); - else if ((tmpadd = (unsigned) inet_addr(buf)) != 0) - memcpy(&add->sin_addr.s_addr, &tmpadd, sizeof(struct in_addr)); + } +#endif else return 0; return 1;