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

2018-04-06 Thread brauner on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2261

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
lxc_make_tmpfile() uses mkstemp() internally, and thus expects the
template to contain 'XX' and be writable.

The existing code in make_anonymous_mount_file() did not work in
case the memfd_create() syscall was not available.

Furthermore, mkstemp() modifies its template argument, hence it
should not be a constant, or undefined behavior can happen. Fixed
both occurrences.

//cc @thmo I tried to push directly to your branch but I think you opted out of this feature. So I'm doing a new pr here. It's really just coding OCD stuff. :)
From a324e7eba0d954ab6f9dafad09efaa67f4aeaa9e Mon Sep 17 00:00:00 2001
From: Christian Brauner 
Date: Fri, 6 Apr 2018 10:54:02 +0200
Subject: [PATCH 1/2] conf: fix temporary file creation

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

Signed-off-by: Thomas Moschny 
Signed-off-by: Christian Brauner 
---
 src/lxc/conf.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 745584308..09095ff9f 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -2286,9 +2286,12 @@ FILE *make_anonymous_mount_file(struct lxc_list *mount)
 
fd = memfd_create(".lxc_mount_file", MFD_CLOEXEC);
if (fd < 0) {
+   char template[] = P_tmpdir "/.lxc_mount_file_XX";
+
if (errno != ENOSYS)
return NULL;
-   fd = lxc_make_tmpfile((char *){P_tmpdir "/.lxc_mount_file"}, 
true);
+
+   fd = lxc_make_tmpfile(template, true);
if (fd < 0) {
SYSERROR("Could not create temporary mount file");
return NULL;

From 709384a02e74f76d59dc6f2903aab1679e9b2839 Mon Sep 17 00:00:00 2001
From: Christian Brauner 
Date: Fri, 6 Apr 2018 10:54:41 +0200
Subject: [PATCH 2/2] ringbuf: fix temporary file creation

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

Signed-off-by: Thomas Moschny 
Signed-off-by: Christian Brauner 
---
 src/lxc/ringbuf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/lxc/ringbuf.c b/src/lxc/ringbuf.c
index 1299fe709..7aa2e6310 100644
--- a/src/lxc/ringbuf.c
+++ b/src/lxc/ringbuf.c
@@ -52,10 +52,12 @@ int lxc_ringbuf_create(struct lxc_ringbuf *buf, size_t size)
 
memfd = memfd_create(".lxc_ringbuf", MFD_CLOEXEC);
if (memfd < 0) {
+   char template[] = P_tmpdir "/.lxc_ringbuf_XX";
+
if (errno != ENOSYS)
goto on_error;
 
-   memfd = lxc_make_tmpfile((char 
*){P_tmpdir"/.lxc_ringbuf_XX"}, true);
+   memfd = lxc_make_tmpfile(template, true);
}
if (memfd < 0)
goto on_error;
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


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

2018-04-06 Thread thmo on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2260

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
lxc_make_tmpfile() uses mkstemp() internally, and thus expects the
template to contain 'XX' and be writable.

The existing code in make_anonymous_mount_file() did not work in
case the memfd_create() syscall was not available.

Furthermore, mkstemp() modifies its template argument, hence it
should not be a constant, or undefined behavior can happen. Fixed
both occurrences.
From 146560a916ba941eb514d43e246bb9f5b0026899 Mon Sep 17 00:00:00 2001
From: Thomas Moschny 
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 'XX' and be writable.

Signed-off-by: Thomas Moschny 
---
 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..8dd29 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_XX";
+   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_XX"}, true);
+   char template[] = P_tmpdir "/.lxc_ringbuf_XX";
+   memfd = lxc_make_tmpfile(template, true);
}
if (memfd < 0)
goto on_error;
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel