From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13817 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Error in getaddrinfo()? Date: Tue, 19 Feb 2019 17:31:45 -0500 Message-ID: <20190219223145.GZ23599@brightrain.aerifal.cx> References: <20190219202700.GB19969@voyager> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="17953"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13833-gllmg-musl=m.gmane.org@lists.openwall.com Tue Feb 19 23:32:01 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1gwDvk-0004Wp-RL for gllmg-musl@m.gmane.org; Tue, 19 Feb 2019 23:32:00 +0100 Original-Received: (qmail 3532 invoked by uid 550); 19 Feb 2019 22:31:58 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3514 invoked from network); 19 Feb 2019 22:31:58 -0000 Content-Disposition: inline In-Reply-To: <20190219202700.GB19969@voyager> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13817 Archived-At: On Tue, Feb 19, 2019 at 09:27:00PM +0100, Markus Wichmann wrote: > Hi all, > > I was just reading the getaddrinfo() source code, and I noticed > something funny. On line 107 we have the wonderful text: > > out[k].slot = i; > > In context, k counts through all the outputs, i counts all the addresses > and j counts the ports. I was wondering about this line and looked for > where slot might be used. Its only use is in freeaddrinfo(), where it is > used to find the head of the output array. But then the slot should be > set to k, right? > > I mean, it works wonderfully in the normal use case, where you call > freeaddrinfo() with the first element of the list. It also works in all > cases if nservs == 1, which is the case if the IPPROTO is set explicitly > in the hints structure. But otherwise? > > According to POSIX, freeaddrinfo() has to support freeing "arbitrary > sublists" of the list originally returned by getaddrinfo(). I presume > that means "tail", because there is no way to free only a certain middle > part of the list. I think you're right, and this should be k, not i. From your reading, will that fix the problem? Rich