From d6490df9a34b435256f634790cb6a63d884bc3fd Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 10 Jul 2015 19:10:28 +0200 Subject: [PATCH] inetd.c: Improve error detection in inet port conversion. Signed-off-by: Joachim Nilsson --- inetd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inetd.c b/inetd.c index ae33bb23..acf25fe7 100644 --- a/inetd.c +++ b/inetd.c @@ -219,15 +219,16 @@ static int getent(char *service, char *proto, struct servent **sv, struct protoe { *sv = getservbyname(service, proto); if (!*sv) { + const char *errstr; static struct servent s; s.s_name = service; - s.s_port = atonum(service); + s.s_port = strtonum(service, 1, UINT16_MAX, &errstr); s.s_proto = NULL; if (!strcmp("tcp", proto) || !strcmp("udp", proto)) s.s_proto = proto; - if (s.s_port == -1 || !s.s_proto) { + if (errstr || !s.s_proto) { _e("Invalid/unknown inetd service, cannot create custom entry."); return errno = EINVAL; }