Patchwork [4/7] Adding ctrl iface command for autoscan

login
register
mail settings
Submitter Tomasz Bursztyka
Date May 3, 2012, 1:16 p.m.
Message ID <1336051016-15005-5-git-send-email-tomasz.bursztyka@linux.intel.com>
Download mbox | patch
Permalink /patch/156696/
State Changes Requested
Headers show

Comments

Tomasz Bursztyka - May 3, 2012, 1:16 p.m.
Signed-hostap: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
---
 wpa_supplicant/ctrl_iface.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
Jouni Malinen - June 24, 2012, 9:59 a.m.
On Thu, May 03, 2012 at 04:16:53PM +0300, Tomasz Bursztyka wrote:
> diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
> +#ifdef CONFIG_AUTOSCAN
> +
> +static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
> +					      char *cmd)
> +{
> +	enum wpa_states state = wpa_s->wpa_state;
> +
> +	if (wpa_s->conf->autoscan != NULL) {
> +		os_free(wpa_s->conf->autoscan);
> +		wpa_s->conf->autoscan = NULL;
> +	}

The previously used parameter should not be cleared before this command
execution has been completed successfully.

> +	if (cmd != NULL && os_strlen(cmd) > 0) {

cmd cannot be NULL here, so that "cmd != NULL && " part is unnecessary.

> +		wpa_s->conf->autoscan = os_strdup(cmd);
> +		if (wpa_s->conf->autoscan == NULL)
> +			return -1;
> +
> +		if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
> +			autoscan_init(wpa_s);
> +	} else if (os_strlen(cmd) == 0)

And if cmd could have been NULL, this would segfault on NULL pointer
dereference..

Patch

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 538f8df..8554094 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -35,6 +35,7 @@ 
 #include "interworking.h"
 #include "blacklist.h"
 #include "wpas_glue.h"
+#include "autoscan.h"
 
 extern struct wpa_driver_ops *wpa_drivers[];
 
@@ -3713,6 +3714,34 @@  static int wpa_supplicant_ctrl_iface_sta_autoconnect(
 }
 
 
+#ifdef CONFIG_AUTOSCAN
+
+static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
+					      char *cmd)
+{
+	enum wpa_states state = wpa_s->wpa_state;
+
+	if (wpa_s->conf->autoscan != NULL) {
+		os_free(wpa_s->conf->autoscan);
+		wpa_s->conf->autoscan = NULL;
+	}
+
+	if (cmd != NULL && os_strlen(cmd) > 0) {
+		wpa_s->conf->autoscan = os_strdup(cmd);
+		if (wpa_s->conf->autoscan == NULL)
+			return -1;
+
+		if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
+			autoscan_init(wpa_s);
+	} else if (os_strlen(cmd) == 0)
+		autoscan_deinit(wpa_s);
+
+	return 0;
+}
+
+#endif /* CONFIG_AUTOSCAN */
+
+
 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
 				      size_t buflen)
 {
@@ -4183,6 +4212,11 @@  char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 	} else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
 		reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
 						       reply_size);
+#ifdef CONFIG_AUTOSCAN
+	} else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
+		if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
+			reply_len = -1;
+#endif /* CONFIG_AUTOSCAN */
 	} else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
 		eapol_sm_request_reauth(wpa_s->eapol);
 	} else {