| 1 |
diff -up dhcp-4.1.0/client/dhclient.c.validate dhcp-4.1.0/client/dhclient.c
|
| 2 |
--- dhcp-4.1.0/client/dhclient.c.validate 2009-01-06 12:11:44.000000000 -1000
|
| 3 |
+++ dhcp-4.1.0/client/dhclient.c 2009-01-06 12:25:06.000000000 -1000
|
| 4 |
@@ -190,7 +190,7 @@ main(int argc, char **argv) {
|
| 5 |
} else if (!strcmp(argv[i], "-p")) {
|
| 6 |
if (++i == argc)
|
| 7 |
usage();
|
| 8 |
- local_port = htons(atoi(argv[i]));
|
| 9 |
+ local_port = validate_port(argv[i]);
|
| 10 |
log_debug("binding to user-specified port %d",
|
| 11 |
ntohs(local_port));
|
| 12 |
} else if (!strcmp(argv[i], "-d")) {
|
| 13 |
diff -up dhcp-4.1.0/common/inet.c.validate dhcp-4.1.0/common/inet.c
|
| 14 |
--- dhcp-4.1.0/common/inet.c.validate 2007-07-12 20:43:41.000000000 -1000
|
| 15 |
+++ dhcp-4.1.0/common/inet.c 2009-01-06 12:11:44.000000000 -1000
|
| 16 |
@@ -604,3 +604,20 @@ piaddrcidr(const struct iaddr *addr, uns
|
| 17 |
return ret;
|
| 18 |
}
|
| 19 |
|
| 20 |
+/* Check the port number specified */
|
| 21 |
+u_int16_t
|
| 22 |
+validate_port(char *port) {
|
| 23 |
+ u_int16_t local_port = 0;
|
| 24 |
+ int lower = 1;
|
| 25 |
+ int upper = 65535;
|
| 26 |
+
|
| 27 |
+ errno = 0;
|
| 28 |
+ local_port = strtol(port, NULL, 10);
|
| 29 |
+ if ((errno == ERANGE) || (errno == EINVAL))
|
| 30 |
+ log_fatal ("Invalid port number specification: %s", port);
|
| 31 |
+
|
| 32 |
+ if (local_port < lower || local_port > upper)
|
| 33 |
+ log_fatal("Port number specified is out of range (%d-%d).", lower, upper);
|
| 34 |
+
|
| 35 |
+ return htons(local_port);
|
| 36 |
+}
|
| 37 |
diff -up dhcp-4.1.0/includes/dhcpd.h.validate dhcp-4.1.0/includes/dhcpd.h
|
| 38 |
--- dhcp-4.1.0/includes/dhcpd.h.validate 2009-01-06 12:11:43.000000000 -1000
|
| 39 |
+++ dhcp-4.1.0/includes/dhcpd.h 2009-01-06 12:11:44.000000000 -1000
|
| 40 |
@@ -65,6 +65,7 @@
|
| 41 |
#endif
|
| 42 |
|
| 43 |
#include <setjmp.h>
|
| 44 |
+#include <errno.h>
|
| 45 |
|
| 46 |
#include "cdefs.h"
|
| 47 |
#include "osdep.h"
|
| 48 |
@@ -2511,6 +2512,7 @@ isc_result_t free_iaddrcidrnetlist(struc
|
| 49 |
const char *piaddr PROTO ((struct iaddr));
|
| 50 |
char *piaddrmask(struct iaddr *, struct iaddr *);
|
| 51 |
char *piaddrcidr(const struct iaddr *, unsigned int);
|
| 52 |
+u_int16_t validate_port(char *port);
|
| 53 |
|
| 54 |
/* dhclient.c */
|
| 55 |
extern int nowait;
|
| 56 |
diff -up dhcp-4.1.0/relay/dhcrelay.c.validate dhcp-4.1.0/relay/dhcrelay.c
|
| 57 |
--- dhcp-4.1.0/relay/dhcrelay.c.validate 2009-01-06 12:11:43.000000000 -1000
|
| 58 |
+++ dhcp-4.1.0/relay/dhcrelay.c 2009-01-06 12:23:29.000000000 -1000
|
| 59 |
@@ -222,7 +222,7 @@ main(int argc, char **argv) {
|
| 60 |
} else if (!strcmp(argv[i], "-p")) {
|
| 61 |
if (++i == argc)
|
| 62 |
usage();
|
| 63 |
- local_port = htons(atoi (argv[i]));
|
| 64 |
+ local_port = validate_port(argv[i]);
|
| 65 |
log_debug("binding to user-specified port %d",
|
| 66 |
ntohs(local_port));
|
| 67 |
} else if (!strcmp(argv[i], "-c")) {
|
| 68 |
diff -up dhcp-4.1.0/server/dhcpd.c.validate dhcp-4.1.0/server/dhcpd.c
|
| 69 |
--- dhcp-4.1.0/server/dhcpd.c.validate 2009-01-06 12:11:43.000000000 -1000
|
| 70 |
+++ dhcp-4.1.0/server/dhcpd.c 2009-01-06 12:11:44.000000000 -1000
|
| 71 |
@@ -298,15 +298,7 @@ main(int argc, char **argv) {
|
| 72 |
if (!strcmp (argv [i], "-p")) {
|
| 73 |
if (++i == argc)
|
| 74 |
usage ();
|
| 75 |
- for (s = argv [i]; *s; s++)
|
| 76 |
- if (!isdigit ((unsigned char)*s))
|
| 77 |
- log_fatal ("%s: not a valid UDP port",
|
| 78 |
- argv [i]);
|
| 79 |
- status = atoi (argv [i]);
|
| 80 |
- if (status < 1 || status > 65535)
|
| 81 |
- log_fatal ("%s: not a valid UDP port",
|
| 82 |
- argv [i]);
|
| 83 |
- local_port = htons (status);
|
| 84 |
+ local_port = validate_port(argv[i]);
|
| 85 |
log_debug ("binding to user-specified port %d",
|
| 86 |
ntohs (local_port));
|
| 87 |
} else if (!strcmp (argv [i], "-f")) {
|
| 88 |
@@ -531,7 +523,7 @@ main(int argc, char **argv) {
|
| 89 |
if (!local_port)
|
| 90 |
{
|
| 91 |
if ((s = getenv ("DHCPD_PORT"))) {
|
| 92 |
- local_port = htons (atoi (s));
|
| 93 |
+ local_port = validate_port(s);
|
| 94 |
log_debug ("binding to environment-specified port %d",
|
| 95 |
ntohs (local_port));
|
| 96 |
} else {
|