]> git.ozlabs.org Git - ppp.git/commitdiff
pppoe: Fail if ethernet interface name is too long
authorPaul Mackerras <paulus@ozlabs.org>
Wed, 8 Nov 2023 05:54:40 +0000 (16:54 +1100)
committerPaul Mackerras <paulus@ozlabs.org>
Wed, 8 Nov 2023 06:05:30 +0000 (17:05 +1100)
If the name of the ethernet interface is longer than can fit in the
relevant structure used for system calls, generate an error rather
than using a truncated interface name.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
pppd/plugins/pppoe/if.c

index 4b13ecc19866eed617fa8ce038d8b2b728ceeba2..d5a4624fce5fe829d61d035847d373bfc94cc4f9 100644 (file)
@@ -99,6 +99,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
     int fd;
     struct ifreq ifr;
     int domain, stype;
+    size_t maxlen;
 
 #ifdef HAVE_STRUCT_SOCKADDR_LL
     struct sockaddr_ll sa;
@@ -111,11 +112,18 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
 #ifdef HAVE_STRUCT_SOCKADDR_LL
     domain = PF_PACKET;
     stype = SOCK_RAW;
+    maxlen = IFNAMSIZ;
 #else
     domain = PF_INET;
     stype = SOCK_PACKET;
+    maxlen = sizeof(sa.sa_data);
 #endif
 
+    if (strlen(ifname) >= maxlen) {
+       error("Can't use interface %.16s: name is too long", ifname);
+       return -1;
+    }
+
     if ((fd = socket(domain, stype, htons(type))) < 0) {
        /* Give a more helpful message for the common error case */
        if (errno == EPERM) {