careful not to thrust h_length from gethostby{name,addr}

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1056 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1996-11-19 21:56:12 +00:00
parent 42ba7456be
commit 99f492acf0
8 changed files with 26 additions and 30 deletions

View File

@@ -60,7 +60,7 @@ hookup(char *host, int port)
int s, len, tos; int s, len, tos;
static char hostnamebuf[80]; static char hostnamebuf[80];
memset((char *)&hisctladdr, 0, sizeof (hisctladdr)); memset(&hisctladdr, 0, sizeof (hisctladdr));
hisctladdr.sin_addr.s_addr = inet_addr(host); hisctladdr.sin_addr.s_addr = inet_addr(host);
if (hisctladdr.sin_addr.s_addr != INADDR_NONE) { if (hisctladdr.sin_addr.s_addr != INADDR_NONE) {
hisctladdr.sin_family = AF_INET; hisctladdr.sin_family = AF_INET;
@@ -73,9 +73,9 @@ hookup(char *host, int port)
return ((char *) 0); return ((char *) 0);
} }
hisctladdr.sin_family = hp->h_addrtype; hisctladdr.sin_family = hp->h_addrtype;
memmove((caddr_t)&hisctladdr.sin_addr, memmove(&hisctladdr.sin_addr,
hp->h_addr_list[0], hp->h_length); hp->h_addr_list[0],
memcpy(&hisctladdr.sin_addr, hp->h_addr, hp->h_length); sizeof(hisctladdr.sin_addr));
strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf)); strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
} }
hostname = hostnamebuf; hostname = hostnamebuf;
@@ -95,8 +95,9 @@ hookup(char *host, int port)
errno = oerrno; errno = oerrno;
warn("connect to address %s", ia); warn("connect to address %s", ia);
hp->h_addr_list++; hp->h_addr_list++;
memmove((caddr_t)&hisctladdr.sin_addr, memmove(&hisctladdr.sin_addr,
hp->h_addr_list[0], hp->h_length); hp->h_addr_list[0],
sizeof(hisctladdr.sin_addr));
fprintf(stdout, "Trying %s...\n", fprintf(stdout, "Trying %s...\n",
inet_ntoa(hisctladdr.sin_addr)); inet_ntoa(hisctladdr.sin_addr));
close(s); close(s);

View File

@@ -1621,16 +1621,6 @@ renamecmd(char *from, char *to)
static void static void
dolog(struct sockaddr_in *sin) dolog(struct sockaddr_in *sin)
{ {
#if 0
struct hostent *hp = gethostbyaddr((char *)&sin->sin_addr,
sizeof(struct in_addr), AF_INET);
if (hp)
strncpy(remotehost, hp->h_name, sizeof(remotehost));
else
strncpy(remotehost, inet_ntoa(sin->sin_addr),
sizeof(remotehost));
#endif
inaddr2str (sin->sin_addr, remotehost, sizeof(remotehost)); inaddr2str (sin->sin_addr, remotehost, sizeof(remotehost));
#ifdef HAVE_SETPROCTITLE #ifdef HAVE_SETPROCTITLE
sprintf(proctitle, "%s: connected", remotehost); sprintf(proctitle, "%s: connected", remotehost);

View File

@@ -150,7 +150,7 @@ get_xsockets (int *unix_socket, int *tcp_socket)
h = gethostbyname ("localhost"); h = gethostbyname ("localhost");
if (h) if (h)
memcpy (&local, h->h_addr, h->h_length); memcpy (&local, h->h_addr, sizeof(local));
else else
local.s_addr = INADDR_LOOPBACK; local.s_addr = INADDR_LOOPBACK;

View File

@@ -128,7 +128,7 @@ connect_host (char *host, char *user, des_cblock *key,
for(p = hostent->h_addr_list; *p; ++p) { for(p = hostent->h_addr_list; *p; ++p) {
int one = 1; int one = 1;
memcpy (&thataddr.sin_addr, *p, hostent->h_length); memcpy (&thataddr.sin_addr, *p, sizeof(thataddr.sin_addr));
s = socket (AF_INET, SOCK_STREAM, 0); s = socket (AF_INET, SOCK_STREAM, 0);
if (s < 0) { if (s < 0) {

View File

@@ -162,7 +162,7 @@ pop_init(POP *p,int argcount,char **argmessage)
p->ipport = ntohs(cs.sin_port); p->ipport = ntohs(cs.sin_port);
/* Get the canonical name of the host to whom I am speaking */ /* Get the canonical name of the host to whom I am speaking */
ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr), AF_INET); ch = gethostbyaddr(&cs.sin_addr, sizeof(cs.sin_addr), AF_INET);
if (ch == NULL){ if (ch == NULL){
pop_log(p,POP_PRIORITY, pop_log(p,POP_PRIORITY,
"Unable to get canonical name of client, err = %d",errno); "Unable to get canonical name of client, err = %d",errno);

View File

@@ -2255,10 +2255,11 @@ int tn(int argc, char **argv)
if (host) { if (host) {
sin.sin_family = host->h_addrtype; sin.sin_family = host->h_addrtype;
#if defined(h_addr) /* In 4.3, this is a #define */ #if defined(h_addr) /* In 4.3, this is a #define */
memmove((caddr_t)&sin.sin_addr, memmove(&sin.sin_addr,
host->h_addr_list[0], host->h_length); host->h_addr_list[0],
sizeof(sin.sin_addr));
#else /* defined(h_addr) */ #else /* defined(h_addr) */
memmove((caddr_t)&sin.sin_addr, host->h_addr, host->h_length); memmove(&sin.sin_addr, host->h_addr, sizeof(sin.sin_addr));
#endif /* defined(h_addr) */ #endif /* defined(h_addr) */
strncpy(_hostname, host->h_name, sizeof(_hostname)); strncpy(_hostname, host->h_name, sizeof(_hostname));
_hostname[sizeof(_hostname)-1] = '\0'; _hostname[sizeof(_hostname)-1] = '\0';
@@ -2351,8 +2352,9 @@ int tn(int argc, char **argv)
errno = oerrno; errno = oerrno;
perror((char *)0); perror((char *)0);
host->h_addr_list++; host->h_addr_list++;
memmove((caddr_t)&sin.sin_addr, memmove(&sin.sin_addr,
host->h_addr_list[0], host->h_length); host->h_addr_list[0],
sizeof(sin.sin_addr));
NetClose(net); NetClose(net);
continue; continue;
} }
@@ -2718,10 +2720,12 @@ sourceroute(arg, cpp, lenp)
sin_addr.s_addr = tmp; sin_addr.s_addr = tmp;
} else if (host = gethostbyname(cp)) { } else if (host = gethostbyname(cp)) {
#if defined(h_addr) #if defined(h_addr)
memmove((caddr_t)&sin_addr, memmove(&sin_addr,
host->h_addr_list[0], host->h_length); host->h_addr_list[0],
sizeof(sin_addr));
#else #else
memmove((caddr_t)&sin_addr, host->h_addr, host->h_length); memmove(&sin_addr, host->h_addr,
sizeof(sin_addr));
#endif #endif
} else { } else {
*cpp = cp; *cpp = cp;

View File

@@ -68,7 +68,7 @@ inaddr2str(struct in_addr addr, char *s, size_t len)
h = gethostbyname (h->h_name); h = gethostbyname (h->h_name);
if(h) if(h)
while ((p = *(h->h_addr_list)++)) while ((p = *(h->h_addr_list)++))
if (memcmp (p, &addr, h->h_length) == 0) { if (memcmp (p, &addr, sizeof(addr)) == 0) {
strncpy (s, h->h_name, len); strncpy (s, h->h_name, len);
s[len - 1] = '\0'; s[len - 1] = '\0';
return; return;

View File

@@ -100,8 +100,9 @@ __ivaliduser(FILE *hostf, u_int32_t raddr, const char *luser, const char *ruser)
#define ypdomain NULL #define ypdomain NULL
#endif #endif
/* We need to get the damn hostname back for netgroup matching. */ /* We need to get the damn hostname back for netgroup matching. */
if ((hp = gethostbyaddr((char *)&raddr, sizeof(u_long), if ((hp = gethostbyaddr((char *)&raddr,
AF_INET)) == NULL) sizeof(u_long),
AF_INET)) == NULL)
return (-1); return (-1);
strncpy(hname, hp->h_name, sizeof(hname)); strncpy(hname, hp->h_name, sizeof(hname));
hname[sizeof(hname) - 1] = '\0'; hname[sizeof(hname) - 1] = '\0';