From owner-freebsd-questions@FreeBSD.ORG Sun Jan 18 23:31:45 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3526516A4CE for ; Sun, 18 Jan 2004 23:31:45 -0800 (PST) Received: from smtp.infracaninophile.co.uk (happy-idiot-talk.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5044643D1D for ; Sun, 18 Jan 2004 23:31:42 -0800 (PST) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [IPv6:::1]) i0J7Vbse008602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 19 Jan 2004 07:31:37 GMT (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost)id i0J7VacJ008601; Mon, 19 Jan 2004 07:31:36 GMT (envelope-from matthew) Date: Mon, 19 Jan 2004 07:31:36 +0000 From: Matthew Seaman To: Saint Aardvark the Carpeted Message-ID: <20040119073136.GA8185@happy-idiot-talk.infracaninophile.co.uk> Mail-Followup-To: Matthew Seaman , Saint Aardvark the Carpeted , freebsd-questions@freebsd.org References: <20040118211958.GP11291@hardesty.saintaardvarkthecarpeted.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="W/nzBZO5zC0uMSeA" Content-Disposition: inline In-Reply-To: <20040118211958.GP11291@hardesty.saintaardvarkthecarpeted.com> User-Agent: Mutt/1.5.5.1i X-Spam-Status: No, hits=-4.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=2.61 X-Spam-Checker-Version: SpamAssassin 2.61 (1.212.2.1-2003-12-09-exp) on happy-idiot-talk.infracaninophile.co.uk cc: freebsd-questions@freebsd.org Subject: Re: ypset(8) attempts to bind to Weird IP (and possible solution) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jan 2004 07:31:45 -0000 --W/nzBZO5zC0uMSeA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jan 18, 2004 at 01:19:58PM -0800, Saint Aardvark the Carpeted wrote: =20 > The problem seems to come in at lines 142/143: before this, > sin.sin_addr.s_addr is localhost (as set at line 130), as is > hent->h_addr_list[0][0]. *After* this, it's set with the Weird IP, > bind_tohost() is called, and packets go off to the Weird IP. >=20 > ObDisclaimer: I Am Not A Programmer, and my knowledge of C is pretty > slim. But: if I change lines 142/143 to: >=20 > bcopy(&hent->h_addr_list[0][0], &sin.sin_addr, sizeof sin.sin_addr); >=20 > then the Weird IP doesn't show up in sin, and ypset only tries to bind > to the IP address listed in its arguments. >=20 > Looking through man pages and header files, it looks like > hostent->h_addr_list is an array of pointers to chars (is that the > right term?): >=20 > char **h_addr_list >=20 > and so gethostbyname is returning the IP address as the *first entry* > in that list. It makes sense to me, then, that bcopy should have > h_addr_list[0][0] as its first argument. Nice analysis. Yes, it looks to me like you've discovered a real bug here. Someone is taking the address of what is already a pointer -- an equivalent to the fix you show would be: bcopy(hent->h_addr_list[0], &sin.sin_addr, sizeof sin.sin_addr); which is possibly slightly clearer as to intent. Another point in your argument would be to convert those weird IP addresses to hexadecimal: 164.110.15.40 =3D 0xa46e0f28 132.110.15.40 =3D 0x846e0f28 and use gdb to compare those values with the contents of the *hent structure. Please do submit a PR with your analysis and a patch. It's slightly perturbing that no-one spotted this a long time ago, but these things happen from time to time. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way PGP: http://www.infracaninophile.co.uk/pgpkey Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK --W/nzBZO5zC0uMSeA Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFAC4fYdtESqEQa7a0RAtPrAKCRRhvNZadt8R9NjSTrihvjMQjVWgCeI0i+ yOoQ8onWxymY7QcsQ4qS00o= =EQgP -----END PGP SIGNATURE----- --W/nzBZO5zC0uMSeA--