[lxc-devel] [lxc/master] Fix temp file creation.

thmo on Github lxc-bot at linuxcontainers.org
Fri Apr 6 08:43:21 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 687 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180406/577c52bd/attachment.bin>
-------------- next part --------------
From 146560a916ba941eb514d43e246bb9f5b0026899 Mon Sep 17 00:00:00 2001
From: Thomas Moschny <thomas.moschny at gmx.de>
Date: Fri, 6 Apr 2018 10:08:18 +0200
Subject: [PATCH] Fix temp file creation.

lxc_make_tmpfile() uses mkstemp() internally, and thus expects the
template to contain 'XXXXXX' and be writable.

Signed-off-by: Thomas Moschny <thomas.moschny at gmx.de>
---
 src/lxc/conf.c    | 4 +++-
 src/lxc/ringbuf.c | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 745584308..8ddaaaa29 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -2288,7 +2288,9 @@ FILE *make_anonymous_mount_file(struct lxc_list *mount)
 	if (fd < 0) {
 		if (errno != ENOSYS)
 			return NULL;
-		fd = lxc_make_tmpfile((char *){P_tmpdir "/.lxc_mount_file"}, true);
+
+		char template[] = P_tmpdir "/.lxc_mount_file_XXXXXX";
+		fd = lxc_make_tmpfile(template, true);
 		if (fd < 0) {
 			SYSERROR("Could not create temporary mount file");
 			return NULL;
diff --git a/src/lxc/ringbuf.c b/src/lxc/ringbuf.c
index 1299fe709..a1b21112a 100644
--- a/src/lxc/ringbuf.c
+++ b/src/lxc/ringbuf.c
@@ -55,7 +55,8 @@ int lxc_ringbuf_create(struct lxc_ringbuf *buf, size_t size)
 		if (errno != ENOSYS)
 			goto on_error;
 
-		memfd = lxc_make_tmpfile((char *){P_tmpdir"/.lxc_ringbuf_XXXXXX"}, true);
+		char template[] = P_tmpdir "/.lxc_ringbuf_XXXXXX";
+		memfd = lxc_make_tmpfile(template, true);
 	}
 	if (memfd < 0)
 		goto on_error;


More information about the lxc-devel mailing list