From bcb393d33649e3ce10d203d149d7ed195964400a Mon Sep 17 00:00:00 2001 From: seshagiriprabhu Date: Tue, 25 Feb 2014 21:21:21 +0530 Subject: [PATCH] Added bound checking for friend ID input in DHT test --- testing/DHT_test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/testing/DHT_test.c b/testing/DHT_test.c index cae88ce4f..3f8b58bdd 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -203,9 +203,12 @@ int main(int argc, char *argv[]) char temp_id[128]; printf("\nEnter the client_id of the friend you wish to add (32 bytes HEX format):\n"); - if (scanf("%s", temp_id) != 1) + if (!fgets(temp_id, sizeof(temp_id), stdin)) exit(0); + if ((strlen(temp_id) > 0) && (temp_id[strlen(temp_id) - 1] == '\n')) + temp_id[strlen(temp_id) - 1] = '\0'; + uint8_t *bin_id = hex_string_to_bin(temp_id); DHT_addfriend(dht, bin_id); free(bin_id);