Author: dcantrel
Update of /cvs/pkgs/rpms/dhcp/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv14981
Modified Files:
dhcp.spec
Added Files:
dhcp-4.0.0-port-validation.patch
Log Message:
* Tue Sep 30 2008 David Cantrell <dcantrell(a)redhat.com> - 12:4.0.0-26
- Validate port numbers for dhclient, dhcpd, and dhcrelay to ensure
that are within the correct range (#438149)
dhcp-4.0.0-port-validation.patch:
--- NEW FILE dhcp-4.0.0-port-validation.patch ---
diff -up dhcp-4.0.0/client/dhclient.c.port dhcp-4.0.0/client/dhclient.c
--- dhcp-4.0.0/client/dhclient.c.port 2008-09-30 14:28:01.000000000 -1000
+++ dhcp-4.0.0/client/dhclient.c 2008-09-30 15:32:04.000000000 -1000
@@ -218,7 +218,7 @@ int main(int argc, char **argv, char **e
} else if (!strcmp (argv [i], "-p")) {
if (++i == argc)
usage ();
- local_port = htons (atoi (argv [i]));
+ local_port = validate_port(argv[i]);
log_debug ("binding to user-specified port %d",
ntohs (local_port));
} else if (!strcmp (argv [i], "-d")) {
diff -up dhcp-4.0.0/common/inet.c.port dhcp-4.0.0/common/inet.c
--- dhcp-4.0.0/common/inet.c.port 2008-09-30 15:30:11.000000000 -1000
+++ dhcp-4.0.0/common/inet.c 2008-09-30 15:36:13.000000000 -1000
@@ -603,3 +603,21 @@ piaddrcidr(const struct iaddr *addr, uns
return ret;
}
+
+/* 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);
+}
diff -up dhcp-4.0.0/includes/dhcpd.h.port dhcp-4.0.0/includes/dhcpd.h
--- dhcp-4.0.0/includes/dhcpd.h.port 2008-09-30 14:28:01.000000000 -1000
+++ dhcp-4.0.0/includes/dhcpd.h 2008-09-30 15:30:36.000000000 -1000
@@ -2432,6 +2432,7 @@ isc_result_t free_iaddrcidrnetlist(struc
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 *);
/* dhclient.c */
extern int nowait;
diff -up dhcp-4.0.0/relay/dhcrelay.c.port dhcp-4.0.0/relay/dhcrelay.c
--- dhcp-4.0.0/relay/dhcrelay.c.port 2007-11-30 11:51:43.000000000 -1000
+++ dhcp-4.0.0/relay/dhcrelay.c 2008-09-30 15:34:24.000000000 -1000
@@ -141,7 +141,7 @@ main(int argc, char **argv) {
if (!strcmp (argv [i], "-p")) {
if (++i == argc)
usage ();
- local_port = htons (atoi (argv [i]));
+ local_port = validate_port(argv[i]);
log_debug ("binding to user-specified port %d",
ntohs (local_port));
} else if (!strcmp (argv [i], "-d")) {
diff -up dhcp-4.0.0/server/dhcpd.c.port dhcp-4.0.0/server/dhcpd.c
--- dhcp-4.0.0/server/dhcpd.c.port 2008-09-30 14:28:00.000000000 -1000
+++ dhcp-4.0.0/server/dhcpd.c 2008-09-30 15:34:01.000000000 -1000
@@ -257,15 +257,7 @@ main(int argc, char **argv) {
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")) {
@@ -438,7 +430,7 @@ main(int argc, char **argv) {
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 {
Index: dhcp.spec
===================================================================
RCS file: /cvs/pkgs/rpms/dhcp/devel/dhcp.spec,v
retrieving revision 1.222
retrieving revision 1.223
diff -u -r1.222 -r1.223
--- dhcp.spec 29 Sep 2008 19:13:30 -0000 1.222
+++ dhcp.spec 1 Oct 2008 01:41:46 -0000 1.223
@@ -4,7 +4,7 @@
Summary: DHCP (Dynamic Host Configuration Protocol) server and relay agent
Name: dhcp
Version: 4.0.0
-Release: 25%{?dist}
+Release: 26%{?dist}
# NEVER CHANGE THE EPOCH on this package. The previous maintainer (prior to
# dcantrell maintaining the package) made incorrect use of the epoch and
# that's why it is at 12 now. It should have never been used, but it was.
@@ -47,6 +47,7 @@
Patch18: %{name}-4.0.0-libdhcp4client.patch
Patch19: %{name}-4.0.0-inherit-leases.patch
Patch20: %{name}-4.0.0-garbage-chars.patch
+Patch21: %{name}-4.0.0-port-validation.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: autoconf
@@ -203,6 +204,10 @@
# Fix 'garbage in format string' error (#450052)
%patch20 -p1
+# Validate port numbers specified for dhclient, dhcpd, and dhcrelay
+# to make sure they are within 1-65535, inclusive. (#438149)
+%patch21 -p1
+
# Copy in documentation and example scripts for LDAP patch to dhcpd
%{__install} -p -m 0644 %{SOURCE5} .
%{__install} -p -m 0644 %{SOURCE6} doc/
@@ -440,6 +445,10 @@
%{_libdir}/libdhcp4client.so
%changelog
+* Tue Sep 30 2008 David Cantrell <dcantrell(a)redhat.com> - 12:4.0.0-26
+- Validate port numbers for dhclient, dhcpd, and dhcrelay to ensure
+ that are within the correct range (#438149)
+
* Mon Sep 29 2008 David Cantrell <dcantrell(a)redhat.com> - 12:4.0.0-25
- Fix dhcpd so it can find configuration data via LDAP (#452985)