]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: backend: make sure to NULL terminate stack buffer
authorNuno Sá <nuno.sa@analog.com>
Tue, 18 Feb 2025 10:31:25 +0000 (10:31 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 4 Mar 2025 13:17:50 +0000 (13:17 +0000)
Make sure to NULL terminate the buffer in
iio_backend_debugfs_write_reg() before passing it to sscanf(). It is a
stack variable so we should not assume it will 0 initialized.

Fixes: cdf01e0809a4 ("iio: backend: add debugFs interface")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250218-dev-iio-misc-v1-1-bf72b20a1eb8@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-backend.c

index d4ad36f54090204bf3bef08457d4aa55aa7c11fc..a43c8d1bb3d0f4dda4277cac94b0ea9232c071e4 100644 (file)
@@ -155,10 +155,12 @@ static ssize_t iio_backend_debugfs_write_reg(struct file *file,
        ssize_t rc;
        int ret;
 
-       rc = simple_write_to_buffer(buf, sizeof(buf), ppos, userbuf, count);
+       rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, count);
        if (rc < 0)
                return rc;
 
+       buf[count] = '\0';
+
        ret = sscanf(buf, "%i %i", &back->cached_reg_addr, &val);
 
        switch (ret) {