From e4b85dae99f201d2b9f3c1d3c4492154ef76a2e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Sat, 31 Jul 2021 20:47:21 +0200 Subject: [PATCH] pppd: Remove usage of incorrect constant MAXIFNAMELEN MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit MAXIFNAMELEN is currently hardcoded to 32, but maximal size of interface name on Linux is just 15 + nul-term byte. This limit is already provided by IFNAMSIZ macro defined in net/if.h header file. So replace MAXIFNAMELEN usage by IFNAMSIZ to not silently truncate interface name. Signed-off-by: Pali Rohár --- pppd/main.c | 2 +- pppd/options.c | 4 ++-- pppd/pppd.h | 5 ++--- pppd/sys-linux.c | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pppd/main.c b/pppd/main.c index db0aa97..203202f 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -124,7 +124,7 @@ /* interface vars */ -char ifname[MAXIFNAMELEN]; /* Interface name */ +char ifname[IFNAMSIZ]; /* Interface name */ int ifunit; /* Interface unit number */ struct channel *the_channel; diff --git a/pppd/options.c b/pppd/options.c index 0c76a6b..f3f5e25 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -121,7 +121,7 @@ int connect_delay = 1000; /* wait this many ms after connect script */ int req_unit = -1; /* requested interface unit */ char path_ipup[MAXPATHLEN]; /* pathname of ip-up script */ char path_ipdown[MAXPATHLEN];/* pathname of ip-down script */ -char req_ifname[MAXIFNAMELEN]; /* requested interface name */ +char req_ifname[IFNAMSIZ]; /* requested interface name */ bool multilink = 0; /* Enable multilink operation */ char *bundle_name = NULL; /* bundle name for multilink */ bool dump_options; /* print out option values */ @@ -299,7 +299,7 @@ option_t general_options[] = { { "ifname", o_string, req_ifname, "Set PPP interface name", - OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, MAXIFNAMELEN }, + OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, IFNAMSIZ }, { "dump", o_bool, &dump_options, "Print out option values after parsing all options", 1 }, diff --git a/pppd/pppd.h b/pppd/pppd.h index 465c1bf..ba62ca5 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -60,6 +60,7 @@ #include /* for u_int32_t, if defined */ #include /* for struct timeval */ #include +#include #include "patchlevel.h" #ifdef INET6 @@ -75,8 +76,6 @@ #define MAXARGS 1 /* max # args to a command */ #define MAXNAMELEN 256 /* max length of hostname or name for auth */ #define MAXSECRETLEN 256 /* max length of password or secret */ -#define MAXIFNAMELEN 32 /* max length of interface name; or use IFNAMSIZ, can we - always include net/if.h? */ /* * If PPP_DRV_NAME is not defined, use the default "ppp" as the device name. @@ -329,7 +328,7 @@ extern int max_data_rate; /* max bytes/sec through charshunt */ extern int req_unit; /* interface unit number to use */ extern char path_ipup[MAXPATHLEN]; /* pathname of ip-up script */ extern char path_ipdown[MAXPATHLEN]; /* pathname of ip-down script */ -extern char req_ifname[MAXIFNAMELEN]; /* interface name to use */ +extern char req_ifname[IFNAMSIZ]; /* interface name to use */ extern bool multilink; /* enable multilink operation */ extern bool noendpoint; /* don't send or accept endpt. discrim. */ extern char *bundle_name; /* bundle name for multilink */ diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index 8f4f2a7..c68dbe1 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -697,7 +697,7 @@ static int make_ppp_unit(void) if (x == 0 && req_ifname[0] != '\0') { struct ifreq ifr; - char t[MAXIFNAMELEN]; + char t[IFNAMSIZ]; memset(&ifr, 0, sizeof(struct ifreq)); slprintf(t, sizeof(t), "%s%d", PPP_DRV_NAME, ifunit); strlcpy(ifr.ifr_name, t, IF_NAMESIZE); -- 2.39.2