Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Unbreak Linux

Fuck. Never save ifr.ifr_name before calling SIOCGIFFLAGS
  • Loading branch information...
commit 390dc64eb974075a5a02f587ab170f4051d56840 1 parent 40ae7c8
Aversiste authored
Showing with 13 additions and 18 deletions.
  1. +13 −18 tuntap-unix-linux.c
31 tuntap-unix-linux.c
View
@@ -70,24 +70,6 @@ tuntap_sys_start(struct device *dev, int mode, int tun) {
return -1;
}
- /* Set the interface name */
- if (tun != TUNTAP_ID_ANY) {
- if (fd > TUNTAP_ID_MAX) {
- tuntap_log(TUNTAP_LOG_ERR, "Can't find a tun entry");
- return -1;
- }
- (void)snprintf(ifr.ifr_name, sizeof ifr.ifr_name,
- ifname, tun);
- /* And save it */
- (void)memcpy(dev->if_name, ifr.ifr_name, sizeof ifr.ifr_name);
- } else {
- /* Get the interface name */
- if (ioctl(fd, TUNGETIFF, &ifr) == -1) {
- tuntap_log(TUNTAP_LOG_ERR, "Can't get interface name");
- return -1;
- }
- }
-
/* Configure the interface */
if (ioctl(fd, TUNSETIFF, &ifr) == -1) {
tuntap_log(TUNTAP_LOG_ERR, "Can't set interface name");
@@ -102,6 +84,16 @@ tuntap_sys_start(struct device *dev, int mode, int tun) {
}
}
+ /* Set the interface name, if any */
+ if (tun != TUNTAP_ID_ANY) {
+ if (fd > TUNTAP_ID_MAX) {
+ return -1;
+ }
+ (void)snprintf(ifr.ifr_name, sizeof ifr.ifr_name,
+ ifname, tun);
+ /* Save interface name *after* SIOCGIFFLAGS */
+ }
+
/* Get the interface default values */
if (ioctl(dev->ctrl_sock, SIOCGIFFLAGS, &ifr) == -1) {
tuntap_log(TUNTAP_LOG_ERR, "Can't get interface values");
@@ -111,6 +103,9 @@ tuntap_sys_start(struct device *dev, int mode, int tun) {
/* Save flags for tuntap_{up, down} */
dev->flags = ifr.ifr_flags;
+ /* Save interface name */
+ (void)memcpy(dev->if_name, ifr.ifr_name, sizeof ifr.ifr_name);
+
/* Save pre-existing MAC address */
if (mode == TUNTAP_MODE_ETHERNET) {
struct ifreq ifr_hw;
Please sign in to comment.
Something went wrong with that request. Please try again.