zlogger: ensure the written data ends with a \0 67/282867/2
authorMateusz Majewski <m.majewski2@samsung.com>
Wed, 12 Oct 2022 12:18:43 +0000 (14:18 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 13 Oct 2022 14:39:27 +0000 (16:39 +0200)
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

kernel/zlogger/zlogger.c

index 4290577..ac7aa4a 100644 (file)
@@ -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;
        }