Module Name: src Committed By: christos Date: Mon Apr 20 14:42:12 UTC 2009
Modified Files: src/include: resolv.h src/lib/libc/resolv: res_init.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/include/resolv.h cvs rdiff -u -r1.19 -r1.20 src/lib/libc/resolv/res_init.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/include/resolv.h diff -u src/include/resolv.h:1.36 src/include/resolv.h:1.37 --- src/include/resolv.h:1.36 Sun Apr 12 13:07:33 2009 +++ src/include/resolv.h Mon Apr 20 10:42:12 2009 @@ -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 @@ 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_ext *ext; /*%< extention for IPv6 */ } _ext; } _u; + u_char *_rnd; /*%< PRIVATE: random state */ #endif }; Index: src/lib/libc/resolv/res_init.c diff -u src/lib/libc/resolv/res_init.c:1.19 src/lib/libc/resolv/res_init.c:1.20 --- src/lib/libc/resolv/res_init.c:1.19 Thu Apr 16 10:56:51 2009 +++ src/lib/libc/resolv/res_init.c Mon Apr 20 10:42:12 2009 @@ -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 @@ 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 @@ } #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 @@ 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 @@ 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 *