1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 14:33:01 +01:00

Fix some lazy/incorrect code in cmd_add()

This fixes a rare but possible scenario where a name@domain lookup that's
longer than a tox id won't work. It also fixes custom messages for domain
lookups
This commit is contained in:
jfreegman 2021-12-07 13:27:38 -05:00
parent 8176b43880
commit 66e4c590dc
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -161,18 +161,12 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
const char *id = argv[1]; const char *id = argv[1];
const size_t arg_length = strlen(id); const size_t arg_length = strlen(id);
const bool is_tox_id = arg_length >= (2 * TOX_ADDRESS_SIZE); const int space_idx = char_find(0, id, ' ');
if (is_tox_id) {
// we have to manually parse the message due to this command being a special case // we have to manually parse the message due to this command being a special case
int idx = char_find(0, id, ' '); if (space_idx > 0 && space_idx < arg_length - 1) {
snprintf(msg, sizeof(msg), "%s", &id[space_idx + 1]);
if (idx > 0 && idx < arg_length - 1) { } else {
snprintf(msg, sizeof(msg), "%s", &id[idx + 1]);
}
}
if (!msg[0]) {
char selfname[TOX_MAX_NAME_LENGTH]; char selfname[TOX_MAX_NAME_LENGTH];
tox_self_get_name(m, (uint8_t *) selfname); tox_self_get_name(m, (uint8_t *) selfname);
@ -183,13 +177,16 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
char id_bin[TOX_ADDRESS_SIZE] = {0}; char id_bin[TOX_ADDRESS_SIZE] = {0};
/* try to add tox ID */ const bool is_tox_id = (char_find(0, id, '@') == arg_length) && (arg_length >= TOX_ADDRESS_SIZE * 2);
if (is_tox_id) {
size_t i;
char xx[3];
uint32_t x;
for (i = 0; i < TOX_ADDRESS_SIZE; ++i) { if (!is_tox_id) {
name_lookup(self, m, id_bin, id, msg);
}
char xx[3];
uint32_t x = 0;
for (size_t i = 0; i < TOX_ADDRESS_SIZE; ++i) {
xx[0] = id[2 * i]; xx[0] = id[2 * i];
xx[1] = id[2 * i + 1]; xx[1] = id[2 * i + 1];
xx[2] = 0; xx[2] = 0;
@ -208,9 +205,6 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
} }
cmd_add_helper(self, m, id_bin, msg); cmd_add_helper(self, m, id_bin, msg);
} else { /* assume id is a username@domain address and do http name server lookup */
name_lookup(self, m, id_bin, id, msg);
}
} }
void cmd_avatar(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_avatar(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])