Skip to contentSkip to conversation

android/client: Fix pin reply call when pin argument missing in cmd

PATCH In review Ravi kumar Veeramally 3 participants 3 messages Nov 1, 2013 – Nov 4, 2013 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 android/client: Fix pin reply call when pin argument missing in cmd

If condition checks number of arguments properly but still executes EXEC command. It should display error message and return.

---
 android/client/if-bt.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
android/client/if-bt.c +7 -4
index 3d97458..2c3cc4a 100644
@@ -719,12 +719,15 @@ static void pin_reply_p(int argc, const char **argv)
 	RETURN_IF_NULL(if_bluetooth);
 	VERIFY_ADDR_ARG(2, &addr);
 
-	if (argc > 3) {
-		accept = 1;
-		pin_len = strlen(argv[3]);
-		memcpy(pin.pin, argv[3], pin_len);
+	if (argc != 4) {
+		haltest_error("Usage <address> <pin>\n");
+		return;
 	}
 
+	accept = 1;
+	pin_len = strlen(argv[3]);
+	memcpy(pin.pin, argv[3], pin_len);
+
 	EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);
 }
 
Signature · 1 line
1.8.1.2
#1 lore raw

Hi Ravi,

Quoted 18 lines · Ravi kumar Veeramally

If condition checks number of arguments properly but still executes EXEC command. It should display error message and return.

---
 android/client/if-bt.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
android/client/if-bt.c +0 -4
index 3d97458..2c3cc4a 100644
@@ -719,12 +719,15 @@ static void pin_reply_p(int argc, const char **argv)
 	RETURN_IF_NULL(if_bluetooth);
 	VERIFY_ADDR_ARG(2, &addr);
 
-	if (argc > 3) {
-		accept = 1;
-		pin_len = strlen(argv[3]);
-		memcpy(pin.pin, argv[3], pin_len);

android/client/if-bt.c static void pin_reply_p(int argc, const char **argv) · line 731

Quoted 10 lines
android/client/if-bt.c +7 -0
+	if (argc != 4) {
+		haltest_error("Usage <address> <pin>\n");
+		return;
 	}
 
+	accept = 1;
+	pin_len = strlen(argv[3]);
+	memcpy(pin.pin, argv[3], pin_len);
+
 	EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);

It seems to me that the original code might have been trying to do (if it hadn't been broken like it now is) a negative pin reply in the case that no parameter was given. At least I don't see any other code trying to call if_bluetooth->pin_reply with accept=1 in haltest. So I'd consider fixing that instead.

Johan

#2 lore raw

Hi Ravi,

Quoted 26 lines · Johan Hedberg

Hi Ravi,

Quoted 23 lines · Ravi kumar Veeramally

If condition checks number of arguments properly but still executes EXEC command. It should display error message and return.

---
 android/client/if-bt.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
android/client/if-bt.c +3 -4
index 3d97458..2c3cc4a 100644
@@ -719,12 +719,15 @@ static void pin_reply_p(int argc, const char **argv)
      RETURN_IF_NULL(if_bluetooth);
      VERIFY_ADDR_ARG(2, &addr);
 
-     if (argc > 3) {
-             accept = 1;
-             pin_len = strlen(argv[3]);
-             memcpy(pin.pin, argv[3], pin_len);
+     if (argc != 4) {
+             haltest_error("Usage <address> <pin>\n");
+             return;
      }
 
Quoted 11 lines

android/client/if-bt.c static void pin_reply_p(int argc, const char **argv) · line 731

Quoted 5 lines
android/client/if-bt.c +4 -0
+     accept = 1;
+     pin_len = strlen(argv[3]);
+     memcpy(pin.pin, argv[3], pin_len);
+
      EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);

It seems to me that the original code might have been trying to do (if it hadn't been broken like it now is) a negative pin reply in the case that no parameter was given. At least I don't see any other code trying to call if_bluetooth->pin_reply with accept=1 in haltest. So I'd consider fixing that instead.

Idea here was: no pin given set accept to 0, so user would not need to type accept argument at all.
What is missing though, is initialization of accept to 0.

Signature · 1 line
Jerzy