about summary refs log tree commit diff
path: root/nss/getent.c
diff options
context:
space:
mode:
Diffstat (limited to 'nss/getent.c')
-rw-r--r--nss/getent.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/nss/getent.c b/nss/getent.c
index 8a3c864501..05ea80825a 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);