Переглянути джерело

getservice: getservent_r must return ERANGE when buffer is too small

This fixes issue introduced by 72e1a1ce186c39f07282398e2af9eb0253e60f15

This should also fix the following testcase to exit with error rather
than cause an endless loop.

int main(void) {
	if (getservbyname("non-existing", "udp") == NULL)
		err(1, "getservbyname");
	return 0;
}

Reported by Pirmin Walthert
http://lists.uclibc.org/pipermail/uclibc/2010-August/044277.html

Signed-off-by: Natanael Copa <natanael.copa@gmail.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Natanael Copa 13 роки тому
батько
коміт
5cb23c3c73
1 змінених файлів з 2 додано та 3 видалено
  1. 2 3
      libc/inet/getservice.c

+ 2 - 3
libc/inet/getservice.c

@@ -69,7 +69,7 @@ int getservent_r(struct servent *result_buf,
 	char **serv_aliases;
 	char **tok = NULL;
 	const size_t aliaslen = sizeof(*serv_aliases) * MAXALIASES;
-	int ret = ENOENT;
+	int ret = ERANGE;
 
 	*result = NULL;
 	if (buflen < aliaslen
@@ -77,7 +77,7 @@ int getservent_r(struct servent *result_buf,
 		goto DONE_NOUNLOCK;
 
 	__UCLIBC_MUTEX_LOCK(mylock);
-
+	ret = ENOENT;
 	if (servp == NULL)
 		setservent(serv_stayopen);
 	if (servp == NULL)
@@ -88,7 +88,6 @@ int getservent_r(struct servent *result_buf,
 	servp->line_len = buflen - aliaslen;
 	/* <name>[[:space:]]<port>/<proto>[[:space:]][<aliases>] */
 	if (!config_read(servp, &tok, MAXALIASES, 3, "# \t/", PARSE_NORMAL)) {
-		ret = ERANGE;
 		goto DONE;
 	}
 	result_buf->s_name = *(tok++);