From: eric Date: Sat, 3 Nov 2018 09:13:24 +0000 (+0000) Subject: For correctness, do not read struct servent if getservbyname_r() failed. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=172d89a7c9bfd1a002b8b73eecc3d14704949255;p=openbsd For correctness, do not read struct servent if getservbyname_r() failed. Also simplify code. --- diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c index 057890f56c6..9bfc0d6c7cd 100644 --- a/lib/libc/asr/getaddrinfo_async.c +++ b/lib/libc/asr/getaddrinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.55 2018/10/22 17:31:24 krw Exp $ */ +/* $OpenBSD: getaddrinfo_async.c,v 1.56 2018/11/03 09:13:24 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -467,7 +467,7 @@ get_port(const char *servname, const char *proto, int numonly) { struct servent se; struct servent_data sed; - int port, r; + int port; const char *e; if (servname == NULL) @@ -482,14 +482,12 @@ get_port(const char *servname, const char *proto, int numonly) if (numonly) return (-2); + port = -1; memset(&sed, 0, sizeof(sed)); - r = getservbyname_r(servname, proto, &se, &sed); - port = ntohs(se.s_port); + if (getservbyname_r(servname, proto, &se, &sed) != -1) + port = ntohs(se.s_port); endservent_r(&sed); - if (r == -1) - return (-1); /* not found */ - return (port); }