1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-03 19:57:45 +02:00

Merge pull request #20 from JFreegman/master

fix buffer overflows and format issues
This commit is contained in:
JFreegman 2013-09-01 15:15:10 -07:00
commit d636cc9780
2 changed files with 10 additions and 9 deletions

View File

@ -72,6 +72,9 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
if (ctx->friendnum != num) if (ctx->friendnum != num)
return; return;
uint8_t nick[TOX_MAX_NAME_LENGTH] = {0};
tox_getname(m, num, (uint8_t *) &nick);
action[len - 1] = '\0'; action[len - 1] = '\0';
wattron(ctx->history, COLOR_PAIR(2)); wattron(ctx->history, COLOR_PAIR(2));
@ -79,7 +82,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
wattroff(ctx->history, COLOR_PAIR(2)); wattroff(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(5)); wattron(ctx->history, COLOR_PAIR(5));
wprintw(ctx->history, "%s\n", action); wprintw(ctx->history, "* %s %s\n", nick, action);
wattroff(ctx->history, COLOR_PAIR(5)); wattroff(ctx->history, COLOR_PAIR(5));
self->blink = true; self->blink = true;
@ -187,7 +190,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
#else #else
if (isprint(key)) { if (isprint(key)) {
#endif #endif
if (ctx->pos != sizeof(ctx->line) - 1) { if (ctx->pos < MAX_STR_SIZE) {
mvwaddstr(self->window, y, x, wc_to_char(key)); mvwaddstr(self->window, y, x, wc_to_char(key));
ctx->line[ctx->pos++] = key; ctx->line[ctx->pos++] = key;
ctx->line[ctx->pos] = L'\0'; ctx->line[ctx->pos] = L'\0';
@ -291,15 +294,13 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd)
wattroff(ctx->history, COLOR_PAIR(2)); wattroff(ctx->history, COLOR_PAIR(2));
uint8_t selfname[TOX_MAX_NAME_LENGTH]; uint8_t selfname[TOX_MAX_NAME_LENGTH];
int len = tox_getselfname(m, selfname, sizeof(selfname)); tox_getselfname(m, selfname, sizeof(selfname));
char msg[MAX_STR_SIZE - len - 4];
snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t *) selfname, action);
wattron(ctx->history, COLOR_PAIR(5)); wattron(ctx->history, COLOR_PAIR(5));
wprintw(ctx->history, msg); wprintw(ctx->history, "* %s %s\n", selfname, action);
wattroff(ctx->history, COLOR_PAIR(5)); wattroff(ctx->history, COLOR_PAIR(5));
if (tox_sendaction(m, ctx->friendnum, (uint8_t *) msg, strlen(msg) + 1) < 0) { if (tox_sendaction(m, ctx->friendnum, (uint8_t *) action, strlen(action) + 1) == 0) {
wattron(ctx->history, COLOR_PAIR(3)); wattron(ctx->history, COLOR_PAIR(3));
wprintw(ctx->history, " * Failed to send action\n"); wprintw(ctx->history, " * Failed to send action\n");
wattroff(ctx->history, COLOR_PAIR(3)); wattroff(ctx->history, COLOR_PAIR(3));

View File

@ -120,7 +120,7 @@ int add_window(Tox *m, ToxWindow w)
void del_window(ToxWindow *w) void del_window(ToxWindow *w)
{ {
active_window = windows; // Go to prompt screen active_window = windows; // Go to prompt screen
delwin(w->window); delwin(w->window);
memset(w, 0, sizeof(ToxWindow)); memset(w, 0, sizeof(ToxWindow));
@ -187,7 +187,7 @@ static void draw_bar()
move(LINES - 1, 0); move(LINES - 1, 0);
attron(COLOR_PAIR(4) | A_BOLD); attron(COLOR_PAIR(4) | A_BOLD);
printw(" TOXIC " TOXICVER "|"); printw(" TOXIC " TOXICVER " |");
attroff(COLOR_PAIR(4) | A_BOLD); attroff(COLOR_PAIR(4) | A_BOLD);
int i; int i;