Преглед на файлове

getservbyport_r: fix out-of-bounds buffer read

If the buffer passed to getservbyport_r is just enough to store two
pointers after aligning it, getnameinfo is called with buflen == 0
(which means that service name is not needed) and trivially succeeds.
Then, strtol is called on the address just past the buffer end, and
if it doesn't happen to find the port number there, getservbyport_r
spuriously succeeds and returns the same bad address to the caller.

Fix this by ensuring that buflen is at least 1 when passed to
getnameinfo.
Alexey Izbyshev преди 2 години
родител
ревизия
595416b11d
променени са 1 файла, в които са добавени 1 реда и са изтрити 1 реда
  1. 1 1
      src/network/getservbyport_r.c

+ 1 - 1
src/network/getservbyport_r.c

@@ -26,7 +26,7 @@ int getservbyport_r(int port, const char *prots,
 	/* Align buffer */
 	i = (uintptr_t)buf & sizeof(char *)-1;
 	if (!i) i = sizeof(char *);
-	if (buflen < 3*sizeof(char *)-i)
+	if (buflen <= 3*sizeof(char *)-i)
 		return ERANGE;
 	buf += sizeof(char *)-i;
 	buflen -= sizeof(char *)-i;