xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xl: close nullfd after dup2'ing it to stdin
@ 2016-02-16 11:35 Ian Campbell
  2016-02-16 13:06 ` Wei Liu
  2016-02-16 17:45 ` Ian Jackson
  0 siblings, 2 replies; 9+ messages in thread
From: Ian Campbell @ 2016-02-16 11:35 UTC (permalink / raw)
  To: ian.jackson, wei.liu2, xen-devel; +Cc: andrew.cooper3, Ian Campbell

Taking care not to do so if nullfd happens (somehow) to have the same
fd number as stdin/out/err.

CID: 1130519

It was previously hypothesised[0] that fixing 1130516 would solve this
too, but that appears to not have been the case.

Compile tested only.

[0] http://lists.xenproject.org/archives/html/xen-devel/2013-11/msg02931.html

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: andrew.cooper3@citrix.com
---
 tools/libxl/xl_cmdimpl.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index d07ccb2..f38e3dd 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -505,6 +505,16 @@ static int do_daemonize(char *name, const char *pidfile)
     dup2(logfile, 1);
     dup2(logfile, 2);
 
+    /* Close nullfd unless it happens to == std{in,out,err} */
+    switch (nullfd) {
+    case 0:
+    case 1:
+    case 2:
+        break;
+    default:
+        close(nullfd);
+    }
+
     CHK_SYSCALL(daemon(0, 1));
 
     if (pidfile) {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-03-01 13:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-16 11:35 [PATCH] xl: close nullfd after dup2'ing it to stdin Ian Campbell
2016-02-16 13:06 ` Wei Liu
2016-02-16 17:45 ` Ian Jackson
2016-02-16 21:54   ` Ian Campbell
2016-02-17 10:39     ` [PATCH v2] " Ian Campbell
2016-02-23 10:30       ` Ian Campbell
2016-02-29 15:45         ` Konrad Rzeszutek Wilk
2016-03-01 12:54           ` Wei Liu
2016-03-01 13:40       ` Ian Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).