Skip to content

Commit

Permalink
The maximum length of an interface name is 16
Browse files Browse the repository at this point in the history
This is described in POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/net_if.h.html

	The <net/if.h> header shall define the following symbolic constant
	for the length of a buffer containing an interface name (including
	the terminating NULL character):

	IF_NAMESIZE
		Interface name length.

Note that proper macro name is IF_NAMESIZE, IFNAMSIZ is the legacy name.

The value of IF_NAMESIZE is usually 16 as far as I can tell, at least on
recent Linux and macOS machines.
  • Loading branch information
DimitriPapadopoulos committed Jan 21, 2021
1 parent b902468 commit 9ffb78c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define OPENFORTIVPN_CONFIG_H

#include <netinet/in.h>
#include <net/if.h>

#include <errno.h>
#include <stdint.h>
Expand Down Expand Up @@ -92,7 +93,7 @@ struct vpn_config {
unsigned int otp_delay;
int no_ftm_push;
char *pinentry;
char iface_name[FIELD_SIZE + 1];
char iface_name[IF_NAMESIZE];
char realm[REALM_SIZE + 1];

int set_routes;
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ int main(int argc, char **argv)
}
if (strcmp(long_options[option_index].name,
"ifname") == 0) {
strncpy(cli_cfg.iface_name, optarg, FIELD_SIZE);
cli_cfg.iface_name[FIELD_SIZE] = '\0';
strncpy(cli_cfg.iface_name, optarg, IF_NAMESIZE - 1);
cli_cfg.iface_name[IF_NAMESIZE - 1] = '\0';
break;
}
if (strcmp(long_options[option_index].name,
Expand Down
8 changes: 4 additions & 4 deletions src/tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ static int tcp_connect(struct tunnel *tunnel)
int ret, handle;
struct sockaddr_in server;
char *env_proxy;
const int iface_len = strnlen(tunnel->config->iface_name, IFNAMSIZ);
const int iface_len = strnlen(tunnel->config->iface_name, IF_NAMESIZE);

handle = socket(AF_INET, SOCK_STREAM, 0);

Expand Down Expand Up @@ -647,7 +647,7 @@ static int tcp_connect(struct tunnel *tunnel)
log_debug("SO_RCVBUF: %d\n", ret);
#endif

if (iface_len == IFNAMSIZ) {
if (iface_len == IF_NAMESIZE) {
log_error("socket: Too long iface name\n");
goto err_post_socket;
}
Expand All @@ -659,8 +659,8 @@ static int tcp_connect(struct tunnel *tunnel)
struct ifreq ifr;

memset(&ifr, 0, sizeof(ifr));
if (strlcpy(ifr.ifr_name, tunnel->config->iface_name, IFNAMSIZ)
>= IFNAMSIZ) {
if (strlcpy(ifr.ifr_name, tunnel->config->iface_name, IF_NAMESIZE)
>= IF_NAMESIZE) {
log_error("interface name too long\n");
goto err_post_socket;
}
Expand Down

0 comments on commit 9ffb78c

Please sign in to comment.