]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
coverity: #1425739
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 6 Dec 2017 20:38:14 +0000 (21:38 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 17 Dec 2017 15:25:29 +0000 (16:25 +0100)
check snprintf() return value

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/tests/snapshot.c

index b035096f1b4600df4bc8c218acb1223033b74db6..1cc07cf0a5deba3f46f219715395e445836eecfe 100644 (file)
@@ -55,6 +55,10 @@ static void try_to_remove(void)
 
 int main(int argc, char *argv[])
 {
+       int i, n, ret;
+       char path[1024];
+       struct stat sb;
+       struct lxc_snapshot *s;
        struct lxc_container *c, *c2 = NULL;
        char *template = "busybox";
 
@@ -89,19 +93,18 @@ int main(int argc, char *argv[])
        }
 
        // rootfs should be ${lxcpath}${lxcname}/snaps/snap0/rootfs
-       struct stat sb;
-       int ret;
-       char path[1024];
-       snprintf(path, 1024, "%s/%s/snaps/snap0/rootfs", lxc_get_global_config_item("lxc.lxcpath"), MYNAME);
+       ret = snprintf(path, 1024, "%s/%s/snaps/snap0/rootfs", lxc_get_global_config_item("lxc.lxcpath"), MYNAME);
+       if (ret < 0 || (size_t)ret >= 1024) {
+               fprintf(stderr, "%s: %d: failed to create string\n", __FILE__, __LINE__);
+               goto err;
+       }
+
        ret = stat(path, &sb);
        if (ret != 0) {
                fprintf(stderr, "%s: %d: snapshot was not actually created\n", __FILE__, __LINE__);
                goto err;
        }
 
-       struct lxc_snapshot *s;
-       int i, n;
-
        n = c->snapshot_list(c, &s);
        if (n < 1) {
                fprintf(stderr, "%s: %d: failed listing containers\n", __FILE__, __LINE__);