[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
actual bug found (I think) in gethostbyname_r() ?
From: |
Greg Herlein |
Subject: |
actual bug found (I think) in gethostbyname_r() ? |
Date: |
Sat, 28 Oct 2000 08:20:37 -0700 (PDT) |
I suspect I see the problem referenced below in the file
getXXent_r.c in the glibc nss directory:
The very end of the function:
int
INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer,
size_t buflen,
LOOKUP_TYPE **result H_ERRNO_PARM)
{
<SNIP>
__libc_lock_unlock (lock);
*result = status == NSS_STATUS_SUCCESS ? resbuf : NULL;
return status == NSS_STATUS_SUCCESS ? 0 : errno;
}
The last line is the problem. It checks if the status is
NSS_STATUS_SUCCESS and if it is it is hardcoded to return a 0 -
which in effect is returning NSS_STATUS_NOTFOUND.
Greg
/**************************************************************
Greg Herlein address@hidden
Herlein Engineering www.herlein.com
***************************************************************/
---------- Forwarded message ----------
Date: Sat, 28 Oct 2000 08:05:10 -0700 (PDT)
From: Greg Herlein <address@hidden>
To: address@hidden
Cc: Thorsten Kukuk <address@hidden>
Subject: incorrect return value in gethostbyname_r() ?
The code below illustrates a problem I have found with
gethostbyname_r(). It is returning NSS_STATUS_NOTFOUND but does
in fact have an answer.
I am using SuSE 6.4, and I upgraded the shared libraries again
just be sure. Here is some info:
address@hidden:~ > ldd getname
libc.so.6 => /lib/libc.so.6 (0x40023000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
address@hidden:~ > gcc -v
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
And, the code that generates the problem:
/* makefile
getname: getname.c
gcc -o getname getname.c -D_REENTRANT
*/
#include <unistd.h>
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <alloca.h>
#include <string.h>
#include <nss.h>
/*----------------------------------------------------------------------*/
int
main(int argc, char* argv[]){
struct hostent he;
struct hostent *rhe;
struct in_addr sSrvAddr;
int herr = 0,n = 0, tmpbuflen = 2048;
char *p, *pHost;
char szSrvAddr[128];
char szBuffer[2048];
if(argc<2)
{
printf("Use: %s <host>\n",argv[0]);
exit(0);
}
pHost=argv[1];
n = gethostbyname_r(pHost, &he,
szBuffer,tmpbuflen,&rhe,&herr);
switch(n)
{
case NSS_STATUS_TRYAGAIN:
case NSS_STATUS_UNAVAIL:
default:
printf("Error getting address\n");
printf("nss_status: %d herr: %d\n",n,herr);
break;
case NSS_STATUS_NOTFOUND:
printf("NSS_STATUS_NOTFOUND...\n");
case NSS_STATUS_SUCCESS:
case NSS_STATUS_RETURN:
sSrvAddr = *((struct in_addr*)rhe->h_addr);
p = inet_ntoa(sSrvAddr);
strncpy(szSrvAddr,p,sizeof(szSrvAddr));
printf("gethostbyname_r: %s = %s\n",pHost,szSrvAddr);
break;
}
return 0;
}
/**************************************************************
Greg Herlein address@hidden
Herlein Engineering www.herlein.com
***************************************************************/
- actual bug found (I think) in gethostbyname_r() ?,
Greg Herlein <=