Bring back binary compatibility with the previous version of the resolver.

There was no room to allocate 16 bytes for _rnd in the struct in the _LP64
case, so we dynamically allocate now. Also put the _rnd field last, so that
we are bitwise compatible too. Now of course we've run out of space, so
next time will need to perform more evil tricks to fit.
This commit is contained in:
christos 2009-04-20 14:42:12 +00:00
parent 7019ec4077
commit 2cca8c559f
2 changed files with 27 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: resolv.h,v 1.36 2009/04/12 17:07:33 christos Exp $ */
/* $NetBSD: resolv.h,v 1.37 2009/04/20 14:42:12 christos Exp $ */
/*
* Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC")
@ -179,11 +179,10 @@ struct __res_state {
int res_h_errno; /*%< last one set for this context */
int _vcsock; /*%< PRIVATE: for res_send VC i/o */
u_int _flags; /*%< PRIVATE: see below */
u_char _rnd[16]; /*%< PRIVATE: random state */
u_int _pad; /*%< make _u 64 bit aligned */
union {
/* On an 32-bit arch this means 512b total. */
char pad[56 - 4*sizeof (int) - 2*sizeof (void *)];
char pad[56 - 4*sizeof (int) - 3*sizeof (void *)];
struct {
uint16_t nscount;
uint16_t nstimes[MAXNS]; /*%< ms. */
@ -191,6 +190,7 @@ struct __res_state {
struct __res_state_ext *ext; /*%< extention for IPv6 */
} _ext;
} _u;
u_char *_rnd; /*%< PRIVATE: random state */
#endif
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: res_init.c,v 1.19 2009/04/16 14:56:51 christos Exp $ */
/* $NetBSD: res_init.c,v 1.20 2009/04/20 14:42:12 christos Exp $ */
/*
* Copyright (c) 1985, 1989, 1993
@ -76,7 +76,7 @@
static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
static const char rcsid[] = "Id: res_init.c,v 1.26 2008/12/11 09:59:00 marka Exp";
#else
__RCSID("$NetBSD: res_init.c,v 1.19 2009/04/16 14:56:51 christos Exp $");
__RCSID("$NetBSD: res_init.c,v 1.20 2009/04/20 14:42:12 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -212,6 +212,7 @@ __res_vinit(res_state statp, int preinit) {
statp->retrans = RES_TIMEOUT;
statp->retry = RES_DFLRETRY;
statp->options = RES_DEFAULT;
statp->_rnd = malloc(16);
res_rndinit(statp);
statp->id = res_nrandomid(statp);
}
@ -685,22 +686,25 @@ net_mask(in) /*!< XXX - should really use system's version of this */
}
#endif
static u_char srnd[16];
void
res_rndinit(res_state statp)
{
struct timeval now;
u_int32_t u32;
u_int16_t u16;
u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd;
gettimeofday(&now, NULL);
u32 = (u_int32_t)now.tv_sec;
memcpy(statp->_rnd, &u32, 4);
memcpy(rnd, &u32, 4);
u32 = now.tv_usec;
memcpy(statp->_rnd + 4, &u32, 4);
memcpy(rnd + 4, &u32, 4);
u32 += (u_int32_t)now.tv_sec;
memcpy(statp->_rnd + 8, &u32, 4);
memcpy(rnd + 8, &u32, 4);
u16 = getpid();
memcpy(statp->_rnd + 12, &u16, 2);
memcpy(rnd + 12, &u16, 2);
}
u_int
@ -708,20 +712,21 @@ res_nrandomid(res_state statp) {
struct timeval now;
u_int16_t u16;
MD5_CTX ctx;
u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd;
gettimeofday(&now, NULL);
u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec);
memcpy(statp->_rnd + 14, &u16, 2);
memcpy(rnd + 14, &u16, 2);
#ifndef HAVE_MD5
MD5_Init(&ctx);
MD5_Update(&ctx, statp->_rnd, 16);
MD5_Final(statp->_rnd, &ctx);
MD5_Update(&ctx, rnd, 16);
MD5_Final(rnd, &ctx);
#else
MD5Init(&ctx);
MD5Update(&ctx, statp->_rnd, 16);
MD5Final(statp->_rnd, &ctx);
MD5Update(&ctx, rnd, 16);
MD5Final(rnd, &ctx);
#endif
memcpy(&u16, statp->_rnd + 14, 2);
memcpy(&u16, rnd + 14, 2);
return ((u_int) u16);
}
@ -752,10 +757,15 @@ res_nclose(res_state statp) {
void
res_ndestroy(res_state statp) {
res_nclose(statp);
if (statp->_u._ext.ext != NULL)
if (statp->_u._ext.ext != NULL) {
free(statp->_u._ext.ext);
statp->_u._ext.ext = NULL;
}
if (statp->_rnd != NULL) {
free(statp->_rnd);
statp->_rnd = NULL;
}
statp->options &= ~RES_INIT;
statp->_u._ext.ext = NULL;
}
const char *