bound checking in messenger testing

This commit is contained in:
seshagiriprabhu 2014-02-25 22:18:27 +05:30
parent bcb393d336
commit 9bb27fbea6

View File

@ -164,9 +164,12 @@ int main(int argc, char *argv[])
char temp_hex_id[128];
printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n");
if (scanf("%s", temp_hex_id) != 1) {
return 1;
}
if (!fgets(temp_hex_id, sizeof(temp_hex_id), stdin))
exit(0);
if ((strlen(temp_hex_id) > 0) && (temp_hex_id[strlen(temp_hex_id) - 1] == '\n'))
temp_hex_id[strlen(temp_hex_id) - 1] = '\0';
uint8_t *bin_id = hex_string_to_bin(temp_hex_id);
int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"));