From 20e953572872308e0f139375bd32400729862611 Mon Sep 17 00:00:00 2001 From: shumbor <55794505+shumbor@users.noreply.github.com> Date: Thu, 15 Oct 2020 15:29:01 +0300 Subject: cli/telnet: fix crash on damaged history file. small check for zero buffer length on load history --- accel-pppd/cli/telnet.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c index 33a82e47..4b5f63ba 100644 --- a/accel-pppd/cli/telnet.c +++ b/accel-pppd/cli/telnet.c @@ -732,11 +732,14 @@ static void load_history_file(void) return; while (fgets((char *)temp_buf, RECV_BUF_SIZE, f)) { - b = _malloc(sizeof(*b) + strlen((char *)temp_buf) + 1); - b->p_buf = NULL; - b->size = strlen((char *)temp_buf) - 1; - memcpy(b->buf, temp_buf, b->size); - list_add_tail(&b->entry, &history); + int buf_len=strlen((char *)temp_buf); + if( buf_len > 0){ + b = _malloc(sizeof(*b) + buf_len + 1); + b->p_buf = NULL; + b->size = buf_len - 1; + memcpy(b->buf, temp_buf, b->size); + list_add_tail(&b->entry, &history); + } } fclose(f); -- cgit v1.2.3