From e4368156e64e04a204d832351abcb535572eb919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20B=C3=ADlka?= Date: Thu, 7 Nov 2013 12:46:57 +0100 Subject: Make getent services compliant with RFC 6335 section 5.1 Fixes bug 15374 The RFC 6335 allows services that start with digit (like 3com-tsmux). These were parsed as port number which this patch fixes. --- nss/getent.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'nss') diff --git a/nss/getent.c b/nss/getent.c index 8a3c864..05ea808 100644 --- a/nss/getent.c +++ b/nss/getent.c @@ -788,8 +788,12 @@ services_keys (int number, char *key[]) if (proto != NULL) *proto++ = '\0'; - if (isdigit (key[i][0])) - serv = getservbyport (htons (atol (key[i])), proto); + char *endptr; + long port = strtol (key[i], &endptr, 10); + + if (isdigit (key[i][0]) && *endptr == '\0' + && 0 <= port && port <= 65535) + serv = getservbyport (htons (port), proto); else serv = getservbyname (key[i], proto); -- cgit v1.1