Received: from hesiod.nhh.no (hesiod.nhh.no [158.37.96.15]) by hub.org (8.8.8/8.8.8) with ESMTP id QAA15295 for ; Fri, 9 Oct 1998 16:38:43 -0400 (EDT) (envelope-from tih@athene.nhh.no) Received: from athene.nhh.no (athene.nhh.no [158.37.96.16]) by hesiod.nhh.no (8.8.8/8.8.8) with ESMTP id WAA01024; Fri, 9 Oct 1998 22:38:39 +0200 (CEST) Received: (from tih@localhost) by athene.nhh.no (8.8.8/8.8.8) id WAA27961; Fri, 9 Oct 1998 22:38:38 +0200 (CEST) Sender: tih@nhh.no To: Tom Lane Cc: Paul A Vixie , hackers@postgreSQL.org Subject: Re: [HACKERS] Open 6.4 items References: <22954.907945289@sss.pgh.pa.us> From: Tom Ivar Helbekkmo Date: 09 Oct 1998 22:38:37 +0200 In-Reply-To: Tom Lane's message of "Fri, 09 Oct 1998 11:01:29 -0400" Message-ID: <86hfxdcvxu.fsf@athene.nhh.no> Lines: 39 X-Mailer: Gnus v5.6.27/Emacs 19.34 Tom Lane writes: > Well, I hate to ruin your day, You sure didn't! You made my day! :-) > but coming pre-armed with the knowledge > that the code is writing one byte too many, it's pretty obvious that the > first loop in inet_net_pton_ipv4 does indeed do that. Specifically at > else if (size-- > 0) > *++dst = 0, dirty = 0; > where, when size (the number of remaining destination bytes) is reduced > to 0, the code nonetheless advances dst and clears the next byte. You're quite right, and I should have caught this one myself, only I must have goofed when I tested the function. (It is written in a style that's just obscure enough that I chose testing it instead of studying it until I understood in detail what it did.) As far as I can tell, the only actual error in Paul Vixie's code is that the two lines you quote above should be: else if (--size > 0) *++dst = 0, dirty = 0; That is, size should be predecremented instead of postdecremented. I'm cc-ing Paul on this, as I assume he wants to get the fix into BIND, which is where inet_net_ntop() and inet_net_pton() came from. > BTW, shouldn't this routine clear out all "size" bytes of the > destination, even if the given data doesn't fill it all? A memset > at the top might be worthwhile. It does: there is code further down that handles that. Another example of the obscure programming style: this function really shows what a low-level language C is! :-) -tih -- Popularity is the hallmark of mediocrity. --Niles Crane, "Frasier"