P2P: Add error message for invalid PIN
authorMasashi Honma <masashi.honma@gmail.com>
Sat, 30 Jun 2012 18:19:12 +0000 (21:19 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 30 Jun 2012 18:19:12 +0000 (21:19 +0300)
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>

wpa_supplicant/ctrl_iface.c

index 64c805d..f3d941b 100644 (file)
@@ -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,