dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
923a60
From 28b5692e9ab3dbb07e4d6b8e44b370637c04ba86 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Sat, 7 Mar 2015 14:19:20 -0500
923a60
Subject: [PATCH] nspawn: fix use-after-free and leak in error paths
923a60
923a60
CID #1257765.
923a60
923a60
(cherry picked from commit 8a16a7b4e7f6702a7e6edaead80ecf04be7d3ba2)
923a60
---
923a60
 src/nspawn/nspawn.c | 4 ++--
923a60
 1 file changed, 2 insertions(+), 2 deletions(-)
923a60
923a60
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
923a60
index 7724df96bd..78bd584834 100644
923a60
--- a/src/nspawn/nspawn.c
923a60
+++ b/src/nspawn/nspawn.c
923a60
@@ -3627,7 +3627,7 @@ int main(int argc, char *argv[]) {
923a60
                 }
923a60
 
923a60
                 if (arg_ephemeral) {
923a60
-                        char *np;
923a60
+                        _cleanup_free_ char *np = NULL;
923a60
 
923a60
                         /* If the specified path is a mount point we
923a60
                          * generate the new snapshot immediately
923a60
@@ -3657,13 +3657,13 @@ int main(int argc, char *argv[]) {
923a60
 
923a60
                         r = btrfs_subvol_snapshot(arg_directory, np, arg_read_only, true);
923a60
                         if (r < 0) {
923a60
-                                free(np);
923a60
                                 log_error_errno(r, "Failed to create snapshot %s from %s: %m", np, arg_directory);
923a60
                                 goto finish;
923a60
                         }
923a60
 
923a60
                         free(arg_directory);
923a60
                         arg_directory = np;
923a60
+                        np = NULL;
923a60
 
923a60
                         remove_subvol = true;
923a60