[257] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

Re: bug in gethostbyname()

daemon@ATHENA.MIT.EDU (Christopher Provenzano)
Fri Feb 9 00:53:00 1996

To: "Jin Guojun[ITG]" <jin@george.lbl.gov>
Cc: pthreads@MIT.EDU
In-Reply-To: Your message of "Wed, 31 Jan 1996 09:51:22 PST."
             <199601311751.JAA28360@george.lbl.gov> 
Date: Fri, 09 Feb 1996 00:37:45 EST
From: Christopher Provenzano  <proven@MIT.EDU>


> In net/gethostbyname.c --
> Line 61 malloc empty structure data->host_answer and passes it to
> gethostbyname_r() in line 67.  It is the "result" in gethostbyname_r() and 
> passed to fake_hostent() without any modification at line 93.
> The first line in fake_hostent() (Global Line # 110), strncpy() tried to
> use an either NULL or garbage result->name pointer which causes core dump.
> 
> 	-Jin
> 
>    107  static struct hostent *fake_hostent(const char *hostname, struct in_a
> ddr  addr,
>    108  struct hostent_answer *result)
>    109  {
>    110          strncpy(result->name, hostname, BUFSIZ - 1);
>    111          result->name[BUFSIZ - 1] = 0;
>    112          result->host.h_name = result->name;
>    113
change name to hostbuf to fix the problem.

	strncpy(result->hostbuf, hostname, BUFSIZ);
	result->hostbuf[BUFSIZ - 1] = 0;
	result->host.h_name = result->hostbuf;

CAP

home help back first fref pref prev next nref lref last post