summaryrefslogtreecommitdiffstats
path: root/main/libc0.9.32/0002-getservice-getservent_r-must-return-ERANGE-when-buff.patch
blob: 29b8c3b3b0346b276a98ad05eb0ce57ac074d102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From 1d1fab81f09e2472921e0b8f1897655de5f9089c Mon Sep 17 00:00:00 2001
From: Natanael Copa <natanael.copa@gmail.com>
Date: Thu, 16 Sep 2010 11:37:39 +0000
Subject: [PATCH 2/3] 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>
---
 libc/inet/getservice.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c
index 1532df9..ccf9816 100644
--- a/libc/inet/getservice.c
+++ b/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++);
-- 
1.7.2.3