pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Ivar Helbekkmo <tih@nhh.no>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Paul A Vixie <vixie@vix.com>
Cc: hackers@postgreSQL.org
Subject: Re: [HACKERS] Open 6.4 items
Date: 09 Oct 1998 22:38:37 +0200
Message-ID: <86hfxdcvxu.fsf@athene.nhh.no> (raw)
References: <22954.907945289@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.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"



view thread (141+ messages)  latest in thread

Message-ID: <86hfxdcvxu.fsf@athene.nhh.no>
Permalink:  ../86hfxdcvxu.fsf@athene.nhh.no/
Also on:    postgresql.org/message-id/86hfxdcvxu.fsf@athene.nhh.no

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tih@nhh.no, tgl@sss.pgh.pa.us, vixie@vix.com, hackers@postgreSQL.org
  Subject: Re: [HACKERS] Open 6.4 items
  In-Reply-To: <86hfxdcvxu.fsf@athene.nhh.no>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox