mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] fix handling of zero length domain names in dn_expand
Date: Thu, 4 Sep 2014 18:41:20 -0400	[thread overview]
Message-ID: <20140904224120.GG23797@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140904221551.GH10361@port70.net>

On Fri, Sep 05, 2014 at 12:15:52AM +0200, Szabolcs Nagy wrote:
> * Rich Felker <dalias@libc.org> [2014-09-04 16:20:53 -0400]:
> > >  	char *dend = dest + (space > 254 ? 254 : space);
> > > -	int len = -1, i, j;
> > > -	if (p==end || !*p) return -1;
> > > +	int len = -1, i, j, first = 1;
> > > +	if (p==end || dest==dend) return -1;
> > 
> > Note that this does nothing to handle negative space, whereas ncopa's
> 
> i assumed it to be ub

Yes, technically it probably should be considered as such, but I was
thinking of crazy things like large buffer lengths silently getting
converted from size_t to int due to the poor choice of types for the
signature. I definitely wouldn't want to treat negative values as
large unsigned values -- this could overflow a small buffer, and real
negatives could happen if "remaining buffer length" was computed
poorly and not checked. One could argue that all of these
considerations are beyond the scope of what the function needs to do,
but checing is easy, and I'm so sick of bugs and potential vulns from
this function already...

> > such. Semantically it seems to be a zero-length component at the end
> > (corresponding to "example.com.." rather than "example.com.", in the
> > notation where final dots are not elided). Understanding whether it's
> > legal or not probably requires some language-lawyering with RFC 1035,
> 
> the rfc is not very clear but i think this case should work
> 
> a name is a sequence of labels terminated by a 0 length label
> 
> a compressed name is a leading sequence of labels terminated
> by a pointer that can be expanded to a name
> 
> if 'sequence of labels' can be empty and the conversion to
> dotted string notation is done after concatenating the
> leading and trailing sequence then there is no '..' issue

OK, based on this explanation, I think both forms are valid. I always
get stuck in the trap of reasoning in the mechanism of conversion
rather than the "sequence of labels" abstraction.

> > -	char *dend = dest + (space > 254 ? 254 : space);
> > +	char *dend;
> >  	int len = -1, i, j;
> > -	if (p==end || !*p) return -1;
> > +	if (p==end || size <= 0) return -1;
> > +	dend = dest + (space > 254 ? 254 : space);
> 
> ok this part is better than mine

Yes, whatever else we do, I think this is a nice addition.

Rich


  reply	other threads:[~2014-09-04 22:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13  8:21 Natanael Copa
     [not found] ` <20140904095039.496f5810@ncopa-desktop.alpinelinux.org>
2014-09-04 17:07   ` Szabolcs Nagy
2014-09-04 18:11     ` Szabolcs Nagy
2014-09-04 20:20       ` Rich Felker
2014-09-04 22:15         ` Szabolcs Nagy
2014-09-04 22:41           ` Rich Felker [this message]
2014-09-04 20:22       ` Natanael Copa

Reply instructions:

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

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

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140904224120.GG23797@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).