From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6722 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Merging ns_parse from Alpine Date: Sun, 14 Dec 2014 17:56:38 -0500 Message-ID: <20141214225638.GH4574@brightrain.aerifal.cx> References: <20141214004320.GA17102@brightrain.aerifal.cx> <20141214073650.GA1330@euler> <20141214172342.GG4574@brightrain.aerifal.cx> <20141214190536.GA11453@euler> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1418597821 2075 80.91.229.3 (14 Dec 2014 22:57:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Dec 2014 22:57:01 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6735-gllmg-musl=m.gmane.org@lists.openwall.com Sun Dec 14 23:56:56 2014 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Y0I5u-0004Do-Ag for gllmg-musl@m.gmane.org; Sun, 14 Dec 2014 23:56:54 +0100 Original-Received: (qmail 3886 invoked by uid 550); 14 Dec 2014 22:56:52 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 3875 invoked from network); 14 Dec 2014 22:56:52 -0000 Content-Disposition: inline In-Reply-To: <20141214190536.GA11453@euler> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:6722 Archived-At: On Sun, Dec 14, 2014 at 08:05:36PM +0100, Felix Janda wrote: > Rich Felker wrote: > > On Sun, Dec 14, 2014 at 08:38:15AM +0100, Felix Janda wrote: > > > Rich Felker wrote: > > > > I'm working on merging Timo's patch for ns_parse: > > > > > > > > http://git.alpinelinux.org/cgit/aports/tree/main/musl/1001-add-basic-dns-record-parsing-functions.patch?id=81d50064c335467fdfd80368bac6707d70db1af7 > > > > > > > > The first issue that came up in the process is that arpa/nameser.h, > > > > which was previously not used by musl itself and really should never > > > > have been accepted in its current form, is full of junk like > > > > statement-expressions. Including it in a file that will be compiled > > > > with musl adds build dependency on these nonstandard features. I > > > > cleaned that up with no problem (just un-inlining the macros since > > > > we're adding function versions anyway), but there are a few more > > > > issues. > > > > > > The NS_GET* macros still seem to be used a lot in the code. > > > > Yes because they also advance the pointer, and this behavior was > > intentional in the code. I don't think it hurts to use them once > > they're fixed to be function calls. > > I likely just missunderstood you. With un-inlining the macros you mean > making them call the ns_get* functions? (That seems reasonable.) Right: #define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2)) #define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4)) #define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2) #define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4) > > > > r = dn_expand(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME); > > > > if (r < 0) return -1; > > > > > > dn_expand doesn't set errno. > > > > Maybe we should just call ns_name_uncompress (below) instead here? > > > > > [...] > > > > int ns_name_uncompress(const unsigned char *msg, const unsigned char *eom, > > > > const unsigned char *src, char *dst, size_t dstsiz) > > > > { > > > > int r; > > > > r = dn_expand(msg, eom, src, dst, dstsiz); > > > > if (r < 0) errno = EMSGSIZE; > > > > return r; > > > > } > > > > Does that sound better? > > That should work. I have no particular opinion on whether to call > ns_name_uncompress or to jump to "size". Indeed, ns_name_uncompress doesn't set any errors except EMSGSIZE. The only ways dn_expand can fail are truncated buffers or malformed messages that would attempt to read outside the buffer, and I think EMSGSIZE is reasonable for either of these. Rich