summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/getservbyname_r.c6
-rw-r--r--src/network/getservbyport_r.c4
2 files changed, 10 insertions, 0 deletions
diff --git a/src/network/getservbyname_r.c b/src/network/getservbyname_r.c
index ad3d6164..cad6317a 100644
--- a/src/network/getservbyname_r.c
+++ b/src/network/getservbyname_r.c
@@ -5,6 +5,7 @@
#include <inttypes.h>
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
#include "lookup.h"
#define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *))
@@ -17,6 +18,11 @@ int getservbyname_r(const char *name, const char *prots,
*res = 0;
+ /* Don't treat numeric port number strings as service records. */
+ char *end = "";
+ strtoul(name, &end, 10);
+ if (!*end) return ENOENT;
+
/* Align buffer */
align = -(uintptr_t)buf & ALIGN-1;
if (buflen < 2*sizeof(char *)+align)
diff --git a/src/network/getservbyport_r.c b/src/network/getservbyport_r.c
index 0ae0e415..b7f21c6b 100644
--- a/src/network/getservbyport_r.c
+++ b/src/network/getservbyport_r.c
@@ -5,6 +5,7 @@
#include <inttypes.h>
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
int getservbyport_r(int port, const char *prots,
struct servent *se, char *buf, size_t buflen, struct servent **res)
@@ -51,6 +52,9 @@ int getservbyport_r(int port, const char *prots,
break;
}
+ /* A numeric port string is not a service record. */
+ if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT;
+
*res = se;
return 0;
}