From 76c00d391a2b9ed8ee02bc3c8db2f67adcbcff82 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 14 Jun 2018 22:10:26 +0200 Subject: [PATCH] coverity: #1425767 Unchecked return value Signed-off-by: Christian Brauner --- src/lxc/storage/btrfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c index be07aeb6f..f22c41747 100644 --- a/src/lxc/storage/btrfs.c +++ b/src/lxc/storage/btrfs.c @@ -659,7 +659,7 @@ static void free_btrfs_tree(struct my_btrfs_tree *tree) static bool do_remove_btrfs_children(struct my_btrfs_tree *tree, u64 root_id, const char *path) { - int i; + int i, ret; char *newpath; size_t len; @@ -675,7 +675,11 @@ static bool do_remove_btrfs_children(struct my_btrfs_tree *tree, u64 root_id, ERROR("Out of memory"); return false; } - snprintf(newpath, len, "%s/%s", path, tree->nodes[i].dirname); + ret = snprintf(newpath, len, "%s/%s", path, tree->nodes[i].dirname); + if (ret < 0 || ret >= len) { + free(newpath); + return false; + } if (!do_remove_btrfs_children(tree, tree->nodes[i].objid, newpath)) { ERROR("Failed to prune %s\n", tree->nodes[i].name); free(newpath);