[libiwinfo] apply FD_CLOEXEC on internal ioctl and netlink sockets
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 3 Oct 2010 18:32:29 +0000 (18:32 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 3 Oct 2010 18:32:29 +0000 (18:32 +0000)
contrib/package/iwinfo/Makefile
contrib/package/iwinfo/src/iwinfo_madwifi.c
contrib/package/iwinfo/src/iwinfo_madwifi.h
contrib/package/iwinfo/src/iwinfo_nl80211.c
contrib/package/iwinfo/src/iwinfo_nl80211.h
contrib/package/iwinfo/src/iwinfo_wext.c
contrib/package/iwinfo/src/iwinfo_wext.h
contrib/package/iwinfo/src/iwinfo_wext_scan.c
contrib/package/iwinfo/src/iwinfo_wext_scan.h
contrib/package/iwinfo/src/iwinfo_wl.c
contrib/package/iwinfo/src/iwinfo_wl.h

index c2b0456dae12b995527e5f17ed34fbb319e14205..0f24945503d6be94d851347a2d9e0f0d9a086f55 100644 (file)
@@ -7,7 +7,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=libiwinfo
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 
index 9b761edfaf0d16031ef9af98e86702f75974d0cb..daecf5df3d065c40cecdbf36bc54f1bcf7992fda 100644 (file)
@@ -202,7 +202,10 @@ static int madwifi_ioctl(struct iwreq *wrq, const char *ifname, int cmd, void *d
 {
        /* prepare socket */
        if( ioctl_socket == -1 )
+       {
                ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
+               fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC);
+       }
 
        strncpy(wrq->ifr_name, ifname, IFNAMSIZ);
 
index 9f9ffe5d8a08e28555862260bc5ef183f2465ff4..1f229183837f90b1a61839e23842fdd10c642f84 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef __IWINFO_MADWIFI_H_
 #define __IWINFO_MADWIFI_H_
 
+#include <fcntl.h>
+
 #include "iwinfo.h"
 #include "include/madwifi.h"
 
index a643efbdc24b4af6c2c6857b7359d5ee6a865ed6..49ddf13fb8695e6a34c1cde28193ae40d9f8632d 100644 (file)
@@ -32,7 +32,7 @@ static struct nl80211_state *nls = NULL;
 
 static int nl80211_init(void)
 {
-       int err;
+       int err, fd;
 
        if( !nls )
        {
@@ -53,6 +53,13 @@ static int nl80211_init(void)
                        goto err;
                }
 
+               fd = nl_socket_get_fd(nls->nl_sock);
+               if( fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC) < 0 )
+               {
+                       err = -EINVAL;
+                       goto err;
+               }
+
                if( genl_ctrl_alloc_cache(nls->nl_sock, &nls->nl_cache)) {
                        err = -ENOMEM;
                        goto err;
@@ -332,6 +339,9 @@ static char * nl80211_wpasupp_info(const char *ifname, const char *cmd)
        remote_length = sizeof(remote.sun_family) + sprintf(remote.sun_path,
                "/var/run/wpa_supplicant-%s/%s", ifname, ifname);
 
+       if( fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC) < 0 )
+               goto out;
+
        if( connect(sock, (struct sockaddr *) &remote, remote_length) )
                goto out;
 
index dd38b960ffcaabd911227ff210e7a3ff5d9a893c..0cf74195d804ece9d349a4e62e8bef6e26b78467 100644 (file)
@@ -20,6 +20,7 @@
 #define __IWINFO_NL80211_H_
 
 #include <errno.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
 #include <sys/socket.h>
index 8fe0305f1d9cf1bdf1128341d267b14744dc375b..7bd1574c1889cd9e6ccb459855087d0d2abd7dcd 100644 (file)
@@ -89,7 +89,10 @@ static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq)
 {
        /* prepare socket */
        if( ioctl_socket == -1 )
+       {
                ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
+               fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC);
+       }
 
        if( !strncmp(ifname, "mon.", 4) )
                strncpy(wrq->ifr_name, &ifname[4], IFNAMSIZ);
index eb2df4f0fe57d6bfefe5b8fc05a752e2b38d74c2..917ea121f097a7a9a290da100adc11ab73312f3a 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef __IWINFO_WEXT_H_
 #define __IWINFO_WEXT_H_
 
+#include <fcntl.h>
+
 #include "iwinfo.h"
 #include "include/wext.h"
 
index b0c1f15e8e72ea379e0ef329f206226784f1982a..f8126183753d67131c2e2d3299ef44c46bf4b33a 100644 (file)
@@ -29,7 +29,10 @@ static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq)
 {
        /* prepare socket */
        if( ioctl_socket == -1 )
+       {
                ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
+               fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC);
+       }
 
        strncpy(wrq->ifr_name, ifname, IFNAMSIZ);
        return ioctl(ioctl_socket, cmd, wrq);
@@ -249,7 +252,7 @@ static inline void wext_fill_wpa(unsigned char *iebuf, int buflen, struct iwinfo
 
                case 0xdd:      /* WPA or else */
                        wpa_oui = wpa1_oui;
-                       /* Not all IEs that start with 0xdd are WPA. 
+                       /* Not all IEs that start with 0xdd are WPA.
                        *        * So check that the OUI is valid. */
                        if((ielen < 8) || ((memcmp(&iebuf[offset], wpa_oui, 3) != 0)
                                && (iebuf[offset+3] == 0x01)))
@@ -477,7 +480,7 @@ int wext_get_scanlist(const char *ifname, char *buf, int *len)
 
        wrq.u.data.pointer = (caddr_t) &range;
        wrq.u.data.length  = sizeof(struct iw_range);
-       wrq.u.data.flags   = 0; 
+       wrq.u.data.flags   = 0;
 
        if( wext_ioctl(ifname, SIOCGIWRANGE, &wrq) >= 0 )
        {
@@ -650,4 +653,3 @@ int wext_get_scanlist(const char *ifname, char *buf, int *len)
 
        return -1;
 }
-
index 2c709a11b435726551f61e1ea6ff3ed6c368df00..6456c28ffdc1860a762e0312c6ea96abafc18014 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef __IWINFO_WEXT_SCAN_H_
 #define __IWINFO_WEXT_SCAN_H_
 
+#include <fcntl.h>
+
 #include "iwinfo.h"
 #include "include/wext.h"
 
@@ -320,7 +322,7 @@ static const struct iw_ioctl_description standard_event_descr[] = {
                .header_type    = IW_HEADER_TYPE_ADDR,
        },
        [IWEVEXPIRED    - IWEVFIRST] = {
-               .header_type    = IW_HEADER_TYPE_ADDR, 
+               .header_type    = IW_HEADER_TYPE_ADDR,
        },
        [IWEVGENIE      - IWEVFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
@@ -328,7 +330,7 @@ static const struct iw_ioctl_description standard_event_descr[] = {
                .max_tokens     = IW_GENERIC_IE_MAX,
        },
        [IWEVMICHAELMICFAILURE  - IWEVFIRST] = {
-               .header_type    = IW_HEADER_TYPE_POINT, 
+               .header_type    = IW_HEADER_TYPE_POINT,
                .token_size     = 1,
                .max_tokens     = sizeof(struct iw_michaelmicfailure),
        },
index 2dac12b1afd944cc38ddb91a0325c8204cec2fbf..81df81faf4a5488456b45250096dd6caa0bf79e3 100644 (file)
@@ -30,7 +30,10 @@ static int wl_ioctl(const char *name, int cmd, void *buf, int len)
 
        /* prepare socket */
        if( ioctl_socket == -1 )
+       {
                ioctl_socket = socket(AF_INET, SOCK_DGRAM, 0);
+               fcntl(ioctl_socket, F_SETFD, fcntl(ioctl_socket, F_GETFD) | FD_CLOEXEC);
+       }
 
        /* do it */
        ioc.cmd = cmd;
index f22f1f3178cd51e686db8c939eec665ece760e0b..0a991a35fe1f7a97aae167c99c4d30c9b2838783 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef __IWINFO_WL_H_
 #define __IWINFO_WL_H_
 
+#include <fcntl.h>
+
 #include "iwinfo.h"
 #include "include/broadcom.h"