Parcourir la source

P2P: Add error message for invalid PIN

Reject invalid PIN value in p2p_connect command. Before this, typos
like "pbd" as the third parameter could have resulted in OK return
value since this parameter was interpreted as the PIN.

Signed-hostap: Masashi Honma <masashi.honma@gmail.com>
Masashi Honma il y a 12 ans
Parent
commit
36ebf7a1b2
1 fichiers modifiés avec 9 ajouts et 0 suppressions
  1. 9 0
      wpa_supplicant/ctrl_iface.c

+ 9 - 0
wpa_supplicant/ctrl_iface.c

@@ -2991,6 +2991,9 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
 	} else if (os_strncmp(pos, "pbc", 3) == 0) {
 		wps_method = WPS_PBC;
 	} else {
+		char *end;
+		long int val;
+
 		pin = pos;
 		pos = os_strchr(pin, ' ');
 		wps_method = WPS_PIN_KEYPAD;
@@ -2999,6 +3002,12 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
 			if (os_strncmp(pos, "display", 7) == 0)
 				wps_method = WPS_PIN_DISPLAY;
 		}
+		val = strtol(pin, &end, 10);
+		if (val < 0 || (os_strlen(pin) != 4 && os_strlen(pin) != 8) ||
+		    *end != '\0') {
+			os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
+			return 17;
+		}
 	}
 
 	new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,