2009-01-06 23:50:29 +00:00
|
|
|
diff -up dhcp-4.1.0/client/dhclient.c.validate dhcp-4.1.0/client/dhclient.c
|
|
|
|
--- dhcp-4.1.0/client/dhclient.c.validate 2009-01-06 12:11:44.000000000 -1000
|
|
|
|
+++ dhcp-4.1.0/client/dhclient.c 2009-01-06 12:25:06.000000000 -1000
|
|
|
|
@@ -190,7 +190,7 @@ main(int argc, char **argv) {
|
|
|
|
} else if (!strcmp(argv[i], "-p")) {
|
2008-10-01 01:41:46 +00:00
|
|
|
if (++i == argc)
|
2009-01-06 23:50:29 +00:00
|
|
|
usage();
|
|
|
|
- local_port = htons(atoi(argv[i]));
|
2008-10-01 01:41:46 +00:00
|
|
|
+ local_port = validate_port(argv[i]);
|
2009-01-06 23:50:29 +00:00
|
|
|
log_debug("binding to user-specified port %d",
|
|
|
|
ntohs(local_port));
|
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
|
|
|
diff -up dhcp-4.1.0/common/inet.c.validate dhcp-4.1.0/common/inet.c
|
|
|
|
--- dhcp-4.1.0/common/inet.c.validate 2007-07-12 20:43:41.000000000 -1000
|
|
|
|
+++ dhcp-4.1.0/common/inet.c 2009-01-06 12:11:44.000000000 -1000
|
2008-10-01 01:58:39 +00:00
|
|
|
@@ -604,3 +604,20 @@ piaddrcidr(const struct iaddr *addr, uns
|
2008-10-01 01:41:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-10-01 01:58:39 +00:00
|
|
|
|
2008-10-01 01:41:46 +00:00
|
|
|
+/* Check the port number specified */
|
|
|
|
+u_int16_t
|
|
|
|
+validate_port(char *port) {
|
|
|
|
+ u_int16_t local_port = 0;
|
|
|
|
+ int lower = 1;
|
|
|
|
+ int upper = 65535;
|
|
|
|
+
|
|
|
|
+ errno = 0;
|
|
|
|
+ local_port = strtol(port, NULL, 10);
|
|
|
|
+ if ((errno == ERANGE) || (errno == EINVAL))
|
|
|
|
+ log_fatal ("Invalid port number specification: %s", port);
|
|
|
|
+
|
|
|
|
+ if (local_port < lower || local_port > upper)
|
|
|
|
+ log_fatal("Port number specified is out of range (%d-%d).", lower, upper);
|
|
|
|
+
|
|
|
|
+ return htons(local_port);
|
|
|
|
+}
|
2009-01-06 23:50:29 +00:00
|
|
|
diff -up dhcp-4.1.0/includes/dhcpd.h.validate dhcp-4.1.0/includes/dhcpd.h
|
|
|
|
--- dhcp-4.1.0/includes/dhcpd.h.validate 2009-01-06 12:11:43.000000000 -1000
|
|
|
|
+++ dhcp-4.1.0/includes/dhcpd.h 2009-01-06 12:11:44.000000000 -1000
|
|
|
|
@@ -65,6 +65,7 @@
|
2008-10-01 02:28:51 +00:00
|
|
|
#endif
|
2008-10-01 01:41:46 +00:00
|
|
|
|
2008-10-01 02:28:51 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
+#include <errno.h>
|
|
|
|
|
|
|
|
#include "cdefs.h"
|
|
|
|
#include "osdep.h"
|
2009-01-06 23:50:29 +00:00
|
|
|
@@ -2511,6 +2512,7 @@ isc_result_t free_iaddrcidrnetlist(struc
|
2008-10-29 23:35:06 +00:00
|
|
|
const char *piaddr PROTO ((struct iaddr));
|
|
|
|
char *piaddrmask(struct iaddr *, struct iaddr *);
|
|
|
|
char *piaddrcidr(const struct iaddr *, unsigned int);
|
|
|
|
+u_int16_t validate_port(char *port);
|
|
|
|
|
|
|
|
/* dhclient.c */
|
|
|
|
extern int nowait;
|
2009-01-06 23:50:29 +00:00
|
|
|
diff -up dhcp-4.1.0/relay/dhcrelay.c.validate dhcp-4.1.0/relay/dhcrelay.c
|
|
|
|
--- dhcp-4.1.0/relay/dhcrelay.c.validate 2009-01-06 12:11:43.000000000 -1000
|
|
|
|
+++ dhcp-4.1.0/relay/dhcrelay.c 2009-01-06 12:23:29.000000000 -1000
|
|
|
|
@@ -222,7 +222,7 @@ main(int argc, char **argv) {
|
|
|
|
} else if (!strcmp(argv[i], "-p")) {
|
2008-10-01 01:41:46 +00:00
|
|
|
if (++i == argc)
|
2009-01-06 23:50:29 +00:00
|
|
|
usage();
|
|
|
|
- local_port = htons(atoi (argv[i]));
|
2008-10-01 01:41:46 +00:00
|
|
|
+ local_port = validate_port(argv[i]);
|
2009-01-06 23:50:29 +00:00
|
|
|
log_debug("binding to user-specified port %d",
|
|
|
|
ntohs(local_port));
|
|
|
|
} else if (!strcmp(argv[i], "-c")) {
|
|
|
|
diff -up dhcp-4.1.0/server/dhcpd.c.validate dhcp-4.1.0/server/dhcpd.c
|
|
|
|
--- dhcp-4.1.0/server/dhcpd.c.validate 2009-01-06 12:11:43.000000000 -1000
|
|
|
|
+++ dhcp-4.1.0/server/dhcpd.c 2009-01-06 12:11:44.000000000 -1000
|
|
|
|
@@ -298,15 +298,7 @@ main(int argc, char **argv) {
|
2008-10-01 01:41:46 +00:00
|
|
|
if (!strcmp (argv [i], "-p")) {
|
|
|
|
if (++i == argc)
|
|
|
|
usage ();
|
|
|
|
- for (s = argv [i]; *s; s++)
|
|
|
|
- if (!isdigit ((unsigned char)*s))
|
|
|
|
- log_fatal ("%s: not a valid UDP port",
|
|
|
|
- argv [i]);
|
|
|
|
- status = atoi (argv [i]);
|
|
|
|
- if (status < 1 || status > 65535)
|
|
|
|
- log_fatal ("%s: not a valid UDP port",
|
|
|
|
- argv [i]);
|
|
|
|
- local_port = htons (status);
|
|
|
|
+ local_port = validate_port(argv[i]);
|
|
|
|
log_debug ("binding to user-specified port %d",
|
|
|
|
ntohs (local_port));
|
|
|
|
} else if (!strcmp (argv [i], "-f")) {
|
2009-01-06 23:50:29 +00:00
|
|
|
@@ -531,7 +523,7 @@ main(int argc, char **argv) {
|
2008-10-01 01:41:46 +00:00
|
|
|
if (!local_port)
|
|
|
|
{
|
|
|
|
if ((s = getenv ("DHCPD_PORT"))) {
|
|
|
|
- local_port = htons (atoi (s));
|
|
|
|
+ local_port = validate_port(s);
|
|
|
|
log_debug ("binding to environment-specified port %d",
|
|
|
|
ntohs (local_port));
|
|
|
|
} else {
|