From: | Tom Ivar Helbekkmo <tih(at)nhh(dot)no> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Paul A Vixie <vixie(at)vix(dot)com>, hackers(at)postgreSQL(dot)org |
Subject: | Re: [HACKERS] Open 6.4 items |
Date: | 1998-10-09 20:38:37 |
Message-ID: | 86hfxdcvxu.fsf@athene.nhh.no |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> 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"
From | Date | Subject | |
---|---|---|---|
Next Message | Brook Milligan | 1998-10-09 21:01:32 | PL compile warning messages |
Previous Message | Bruce Momjian | 1998-10-09 20:24:14 | backslash in psql output |