Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] android/client: Check if hex string is byte format
@ 2014-09-05 13:55 Grzegorz Kolodziejczyk
  2014-09-09 11:06 ` Szymon Janc
  0 siblings, 1 reply; 2+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-09-05 13:55 UTC (permalink / raw)
  To: linux-bluetooth

Data strings should be byte format.
---
 android/client/if-gatt.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/android/client/if-gatt.c b/android/client/if-gatt.c
index c8352b5..0dee225 100644
--- a/android/client/if-gatt.c
+++ b/android/client/if-gatt.c
@@ -114,11 +114,17 @@ const btgatt_interface_t *if_gatt = NULL;
 
 #define GET_VERIFY_HEX_STRING(n, v, l) \
 	do { \
+		int ll;\
 		if (n[0] != '0' || (n[1] != 'X' && n[1] != 'x')) { \
 			haltest_error("Value must be hex string\n"); \
 			return; \
 		} \
-		l = fill_buffer(n + 2, (uint8_t *) v, sizeof(v)); \
+		ll = fill_buffer(n + 2, (uint8_t *) v, sizeof(v)); \
+		if (ll < 0) { \
+			haltest_error("Value must be byte hex string\n"); \
+			return; \
+		} \
+		l = ll; \
 	} while (0)
 
 /* Gatt uses little endian uuid */
@@ -803,6 +809,10 @@ static int fill_buffer(const char *str, uint8_t *out, int out_size)
 
 	str_len = strlen(str);
 
+	/* Hex string must be byte format */
+	if (str_len%2 != 0)
+		return -1;
+
 	for (i = 0, j = 0; i < out_size && j < str_len; i++, j++) {
 		c = str[j];
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-09 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-05 13:55 [PATCH] android/client: Check if hex string is byte format Grzegorz Kolodziejczyk
2014-09-09 11:06 ` Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox