From 0dde733e5a049e695885d733eb98795b0eddbd74 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 28 Oct 2020 04:04:42 +0100 Subject: [PATCH] utils: check snprintf return value Fixes: Coverity 1465853 Signed-off-by: Christian Brauner --- src/lxc/utils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 561f7685c..baf80b7f5 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -1097,7 +1097,9 @@ int __safe_mount_beneath_at(int beneath_fd, const char *src, const char *dst, co target_fd = openat2(beneath_fd, dst, &how, sizeof(how)); if (target_fd < 0) return -errno; - snprintf(tgt_buf, sizeof(tgt_buf), "/proc/self/fd/%d", target_fd); + ret = snprintf(tgt_buf, sizeof(tgt_buf), "/proc/self/fd/%d", target_fd); + if (ret < 0 || ret >= sizeof(tgt_buf)) + return -EIO; if (!is_empty_string(src_buf)) ret = mount(src_buf, tgt_buf, fstype, flags, data); -- 2.47.2