From 445f5aa1fde42ea0d3997be15620a6963f519342 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 23 May 2014 23:14:44 -0400 Subject: [PATCH] fix possible buffer overflow --- src/chat.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/chat.c b/src/chat.c index 8d9e7bb..9cb3c00 100644 --- a/src/chat.c +++ b/src/chat.c @@ -252,8 +252,15 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filename[len] = '\0'; char d[9]; sprintf(d, "(%d)", count++); + int d_len = strlen(d); + + if (len + d_len >= sizeof(filename)) { + len -= d_len; + filename[len] = '\0'; + } + strcat(filename, d); - filename[len + strlen(d)] = '\0'; + filename[len + d_len] = '\0';; if (count > 999) { errmsg = "Error saving file to disk.";