mailing list of musl libc
 help / color / mirror / code / Atom feed
* Error in getaddrinfo()?
@ 2019-02-19 20:27 Markus Wichmann
  2019-02-19 21:09 ` Michael Forney
  2019-02-19 22:31 ` Rich Felker
  0 siblings, 2 replies; 5+ messages in thread
From: Markus Wichmann @ 2019-02-19 20:27 UTC (permalink / raw)
  To: musl

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.

And while we're on the subject, a few lines later we get

			.ai_next = &out[k+1].ai };

Now, for the last k, isn't this calculation undefined? The array index
is out of bounds, then. It won't matter what is calculated here, since
the last .ai_next is explicitly nulled a few lines further down, but the
calculation might invoke undefined behavior, and these last few years
compilers have gotten really agressive about that.

Ciao,
Markus


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-20 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-19 20:27 Error in getaddrinfo()? Markus Wichmann
2019-02-19 21:09 ` Michael Forney
2019-02-19 22:30   ` Rich Felker
2019-02-19 22:31 ` Rich Felker
2019-02-20 15:21   ` Markus Wichmann

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).