Operating System - HP-UX
1826341 Members
4121 Online
109692 Solutions
New Discussion

Re: gethostbyname fails with core dump

 
Dubost_2
Advisor

gethostbyname fails with core dump

The following program fails with a core dump in gethostbyname on a computer running HP-UX 11.11. It is compiled with aCC and linked with some shared libraries. It works fine on other computers or when not linked with the shared libraries. Has anybody an idea of what happens?

#include

int main( int argc, char *argv[] )
{
struct hostent * toto ;

printf( "Call gethostbyname\n" );
toto = gethostbyname( "tam2012" );
printf("gethostbyname return 0x%08x\n", toto );
}
14 REPLIES 14
A. Clay Stephenson
Acclaimed Contributor

Re: gethostbyname fails with core dump

PHCO_28605 (which requires PHCO_24402) fixes a buffer overflow in gethostbyname() and could easily be your problem. I would also look at libc patches (PHCO_33533).

Of course, the thing to do is get a stack trace.
If it ain't broke, I can fix that.
Dubost_2
Advisor

Re: gethostbyname fails with core dump

Thanks for your help.
I installed the patchs you were talking about and the result is the same.

Here is a stack trace

#0 0xc0137b30 in $$dyncall_external+0 () from /usr/lib/libc.2
(gdb) bt
#0 0xc0137b30 in $$dyncall_external+0 () from /usr/lib/libc.2
#1 0xc021f590 in __thread_once+0x78 () from /usr/lib/libc.2
#2 0xc00add08 in ent2result+0x3c () from /usr/lib/libnss_dns.1
#3 0xb9980 in nss_search+0x258 () from /opt/a1338/bin/./udpCGS
#4 0x71b50 in __gethostbyname_r+0x12c () from /opt/a1338/bin/./udpCGS
#5 0x71cac in gethostbyname+0x7c () from /opt/a1338/bin/./udpCGS
#6 0x20d44 in main (argc=1, argv=0x7b040454) at /a1338_mnt_dev/dubost/5.00/dev/udpCGS/src/udpCGS.c:354

Best regards.
Peter Nikitka
Honored Contributor

Re: gethostbyname fails with core dump

Hi,

perhaps there is no memory allocated for the struct. Try this:

#include
#include

int main( int argc, char *argv[] )
{
struct hostent hhh;
struct hostent *toto = &hhh;

printf( "Call gethostbyname\n" );
toto = gethostbyname(argv[1]);
printf("gethostbyname return %s\n", toto->h_name);
}

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Stephen Keane
Honored Contributor

Re: gethostbyname fails with core dump

gethostbyname() will return a NULL pointer if the named host cannot be found. You are then trying to print something from a structure pointed to by potentially a NULL pointer which would core dump. Check the return value of gethostbyname() first!

toto = gethostbyname( "tam2012" );

if (toto == (struct hostent *) NULL)
{
printf("couldn't find host!\n");
}
else
{
printf("gethostbyname return 0x%08x\n", toto );
}
Dubost_2
Advisor

Re: gethostbyname fails with core dump

Thanks for your help
In fact, gethostbyname does not return.
It core dumps.
I suspect a problem with shared libraries.
The program is linked with shared libraries.
If I don't link with the libraries, everything goes fine.
Stephen Keane
Honored Contributor

Re: gethostbyname fails with core dump

Sorry, wasn't clear on that point! :)

In which case, what does

# ldd your_exe

give you ?
Muthukumar_5
Honored Contributor

Re: gethostbyname fails with core dump

Include stdlib.h header file, compile and run it. Are you getting it now?

#include
#include

int main( int argc, char *argv[] )
{
struct hostent * toto ;

printf( "Call gethostbyname\n" );
toto = gethostbyname( "tam2012" );
printf("gethostbyname return 0x%08x\n", toto );
return 0;
}

If you get core still, paste informations for,

# file core
# what core

hth.
Easy to suggest when don't know about the problem!
VEL_1
Valued Contributor

Re: gethostbyname fails with core dump

Dubost_2
Advisor

Re: gethostbyname fails with core dump

Here is the result of "ldd udpCGS" :

/usr/lib/libdld.2 => /usr/lib/libdld.2
/usr/lib/libc.2 => /usr/lib/libc.2
/usr/lib/libdld.2 => /usr/lib/libdld.2
/a1338_mnt_dev/dubost/5.00/dev/api_cxx/src/Msg_Daily/build/HPUX11-00-debug/libMsg_Daily.sl => /a1338_mnt_dev/dubost/5.00/dev/api_cxx/src/Msg_Daily/build/HPUX11-00-debug/libMsg_Daily.sl
/a1338_mnt_dev/dubost/5.00/dev/adm-conf/CS_src/adminComm/build/HPUX11-00-debug/libadminComm.sl => /a1338_mnt_dev/dubost/5.00/dev/adm-conf/CS_src/adminComm/build/HPUX11-00-debug/libadminComm.sl
r

Here is the result of "file core" :

core: core file from 'udpCGS' - received SIGBUS

Here is the result of "what core" :

core:
$Header: /cgw_cvs/dev/udpCGS/src/udpCGS.c,v 5.000 2005/09/12 09:47:23 dupety Exp $
$Header: /cgw_cvs/dev/common/include/common.h,v 5.000 2005/09/12 08:34:17 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/common/src/com_conf.c,v 5.000 2005/09/12 08:34:26 dupety Exp $ $Name: $
HPUX11_00 $Header: /cgw_cvs/dev/common/include/CDRC-portability.h,v 5.000 2005/09/12 08:34:04 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/common/include/common.h,v 5.000 2005/09/12 08:34:17 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/common/src/com_log.c,v 4.500.2.1.4.2 2005/09/07 07:26:09 dupety Exp $ $Name: $
HPUX11_00 $Header: /cgw_cvs/dev/common/include/CDRC-portability.h,v 5.000 2005/09/12 08:34:04 dupety Exp $ $Name: $
$ PATCH/11.00:PHCO_28425 Mar 4 2003 07:15:43 $
$Revision: libxti.2: STREAMS: PATCH_11.11 (PHNE_27703) Fri Sep 27 13:18:08 PDT 2002 $
$Header: /cgw_cvs/dev/common/include/common.h,v 5.000 2005/09/12 08:34:17 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/adm-conf/CS_src/comm_functions.c,v 4.500.2.2 2005/07/11 14:12:58 dupety Exp $
$Header: /cgw_cvs/dev/adm-conf/CS_src/comm_functions.h,v 4.500.2.2 2005/07/11 14:14:31 dupety Exp $
$Header: /cgw_cvs/dev/adm-conf/common_src/adm_nmc.h,v 4.500 2005/03/29 13:34:06 dupety Exp $
HPUX11_00 $Header: /cgw_cvs/dev/common/include/CDRC-portability.h,v 5.000 2005/09/12 08:34:04 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/common/include/common.h,v 5.000 2005/09/12 08:34:17 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/api_cxx/src/Msg_Daily/Msg_Daily.cc,v 5.000 2005/09/12 08:33:15 dupety Exp $
HPUX11_00 $Header: /cgw_cvs/dev/common/include/CDRC-portability.h,v 5.000 2005/09/12 08:34:04 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/common/include/common.h,v 5.000 2005/09/12 08:34:17 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/api_cxx/src/Msg_Daily/api_Msg_Daily.cc,v 5.000 2005/09/12 08:33:20 dupety Exp $
HPUX11_00 $Header: /cgw_cvs/dev/common/include/CDRC-portability.h,v 5.000 2005/09/12 08:34:04 dupety Exp $ $Name: $
$Header: /cgw_cvs/dev/api_cxx/src/ErrHandler/ErrHandler.cc,v 5.000 2005/09/12 08:33:23 dupety Exp $
HPUX11_00 $Header: /cgw_cvs/dev/common/include/CDRC-portability.h,v 5.000 2005/09/12 08:34:04 dupety Exp $ $Name: $
$ PATCH_11.11/PHCO_33533 Jul 27 2005 02:12:39 $
SMART_BIND
92453-07 dld dld dld.sl B.11.43 050125

Thanks for your help.
VEL_1
Valued Contributor

Re: gethostbyname fails with core dump

Muthukumar_5
Honored Contributor

Re: gethostbyname fails with core dump

What is the compliation option you are using? I was experiencing same SIGBUS signal with thread programming. I hope you need to add few compiler flags. I will update on getting that.

Before that, enable debug option -g with compiler and get gdb stack trace for core?

hth.
Easy to suggest when don't know about the problem!
Dubost_2
Advisor

Re: gethostbyname fails with core dump

Compiler is aCC.

Compilation flags are :
-c -g

Compilation defines are :
-DHPUX11_00 -D_DEBUG_ -DHPUX -D_REENTRANT

Link flags are:
-z -Z -Wl,+s,-a,shared_archive -AA -L/usr/lib -Wl,-a,archive -lpthread

Stack trace is already given in the thread.

Thanks for your help
Stephen Keane
Honored Contributor

Re: gethostbyname fails with core dump

You have read

WARNINGS

Programs that use the interfaces described in this manpage cannot be linked statically because the implementations of these functions employ dynamic loading and inking of shared objects at run time.

In the man page?
Dubost_2
Advisor

Re: gethostbyname fails with core dump

I tried to install the latest patchs for the C and C++ libraries and I have now a new error at the init of my program and before any function is called :

#0 0xc020e5d8 in kill+0x10 () from /usr/lib/libc.2
#1 0xc01a71c4 in raise+0x24 () from /usr/lib/libc.2
#2 0xc01e9170 in abort_C+0x160 () from /usr/lib/libc.2
#3 0xc01e91cc in abort+0x1c () from /usr/lib/libc.2
#4 0xc0e3383c in std::terminate+0x38 () from /usr/lib/libCsup_v2.2
#5 0xc0e33cf4 in ThrowException+0x70 () from /usr/lib/libCsup_v2.2
#6 0xc0e34254 in __throw__FPvT1+0x14c () from /usr/lib/libCsup_v2.2
#7 0xc356e6cc in std::ios_base::setf+0x78 () from /usr/lib/libstd_v2.2
#8 0xc356e194 in std::ios_base::Init::Init+0x1df0 () from /usr/lib/libstd_v2.2
#9 0xc3224814 in std::__sinit_Msg_Daily_cc+0x24 () from /opt/a1338/lib/libMsg_Daily.sl
#10 0xc0e35ce0 in __shlInit+0x88 () from /usr/lib/libCsup_v2.2
#11 0xc32148b8 in _shlInit+0x20 () from /opt/a1338/lib/libMsg_Daily.sl
#12 0xc0e35618 in __shlinit+0xac () from /usr/lib/libCsup_v2.2
#13 0xc0e37b30 in _main+0xd8 () from /usr/lib/libCsup_v2.2

What can I do with this. Thank for your help