]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS NFC: Validate ctrl_iface response before decoding it
authorJouni Malinen <jouni@qca.qualcomm.com>
Fri, 29 Nov 2013 10:46:41 +0000 (12:46 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 27 Jan 2014 20:08:13 +0000 (22:08 +0200)
If the operation fails for any reason ("FAIL" response), it is cleaner
to return error clearly instead of hitting an exception in the hex
decoder.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

wpa_supplicant/examples/wps-nfc.py

index e1d59e96a96c61b864a207f74829e104f85d7cfb..ea00497cdd517cad6a8bfcb06e813730f2a75baa 100755 (executable)
@@ -75,7 +75,10 @@ def wpas_get_er_config_token(uuid):
     wpas = wpas_connect()
     if (wpas == None):
         return None
-    return wpas.request("WPS_ER_NFC_CONFIG_TOKEN NDEF " + uuid).rstrip().decode("hex")
+    ret = wpas.request("WPS_ER_NFC_CONFIG_TOKEN NDEF " + uuid)
+    if "FAIL" in ret:
+        return None
+    return ret.rstrip().decode("hex")
 
 
 def wpas_get_password_token():
@@ -97,8 +100,12 @@ def wpas_get_handover_sel(uuid):
     if (wpas == None):
         return None
     if uuid is None:
-        return wpas.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip().decode("hex")
-    return wpas.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + uuid).rstrip().decode("hex")
+        res = wpas.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
+    else:
+       res = wpas.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + uuid).rstrip()
+    if "FAIL" in res:
+       return None
+    return res.decode("hex")
 
 
 def wpas_report_handover(req, sel, type):