From: Nuno Sá Date: Tue, 18 Feb 2025 10:31:25 +0000 (+0000) Subject: iio: backend: make sure to NULL terminate stack buffer X-Git-Tag: v6.15-rc1~78^2~8^2~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=035b4989211dc1c8626e186d655ae8ca5141bb73;p=thirdparty%2Fkernel%2Flinux.git iio: backend: make sure to NULL terminate stack buffer 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á Reviewed-by: David Lechner Link: https://patch.msgid.link/20250218-dev-iio-misc-v1-1-bf72b20a1eb8@analog.com Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index d4ad36f540902..a43c8d1bb3d0f 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -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) {