From: Mateusz Majewski Date: Wed, 12 Oct 2022 12:18:43 +0000 (+0200) Subject: zlogger: ensure the written data ends with a \0 X-Git-Tag: accepted/tizen/unified/20221102.172737~6^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=297b874dd575bf0b603b6ba324a3e416e4edbc66;p=platform%2Fkernel%2Flinux-tizen-modules-source.git zlogger: ensure the written data ends with a \0 This is necessary, as the function relies on strnlen in order to determine how many bytes to write, and at the same time it doesn't guarantee that the whole buffer is being written (the buffer is only enlarged, never shrunk). Change-Id: I1a761ae61aee888f16e9243a136dec8c9b76b7ec --- diff --git a/kernel/zlogger/zlogger.c b/kernel/zlogger/zlogger.c index 4290577..ac7aa4a 100644 --- a/kernel/zlogger/zlogger.c +++ b/kernel/zlogger/zlogger.c @@ -513,6 +513,8 @@ static void endl_to_zero(struct zlog_file *zlog_file_data, size_t len) *cb = '\0'; cb++; } + + *cb = '\0'; } static ssize_t partition_write_buffer(struct zlog_file *zlog_file_data, size_t len) @@ -555,7 +557,7 @@ static ssize_t zlogger_write(struct file *filep, const char __user *buffer, size zlog_file_data = (struct zlog_file *)filep->private_data; - if (len > zlog_file_data->buffer_len && !update_zlog_data_buffer_size(zlog_file_data, len)) { + if (len >= zlog_file_data->buffer_len && !update_zlog_data_buffer_size(zlog_file_data, len + 1)) { pr_err("update_zlog_data_buffer_size failed\n"); return -ENOMEM; }