From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Daley Subject: [PATCH 11/13] libxl: use pipe instead of temporary file for VNC viewer --autopass Date: Sun, 1 Dec 2013 23:15:05 +1300 Message-ID: <1385892907-20084-12-git-send-email-mattd@bugfuzz.com> References: <1385892907-20084-1-git-send-email-mattd@bugfuzz.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1385892907-20084-1-git-send-email-mattd@bugfuzz.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Matthew Daley , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Coverity was complaining about the permissions implicitly set on the temporary file used to pass the VNC password to the viewer when using the --autopass feature. By replacing the use of the temporary file with a pipe, we fix the problem (well, quiesce Coverity at least), tidy the code and remove the buildup of temporary file cruft all at once. Tested with TightVNC. Coverity-ID: 1055958 Signed-off-by: Matthew Daley --- tools/libxl/libxl.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index ca4c2cd..41b8f60 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1623,7 +1623,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass) GC_INIT(ctx); const char *vnc_port; const char *vnc_listen = NULL, *vnc_pass = NULL; - int port = 0, autopass_fd = -1; + int port = 0, autopass_fds[2] = {-1, -1}; char *vnc_bin, *args[] = { "vncviewer", NULL, /* hostname:display */ @@ -1655,38 +1655,30 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass) args[1] = libxl__sprintf(gc, "%s:%d", vnc_listen, port); if ( vnc_pass ) { - char tmpname[] = "/tmp/vncautopass.XXXXXX"; - autopass_fd = mkstemp(tmpname); - if ( autopass_fd < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "mkstemp %s failed", tmpname); - goto x_fail; - } - - if ( unlink(tmpname) ) { - /* should never happen */ - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "unlink %s failed", tmpname); + if ( pipe(autopass_fds) < 0 ) { + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "pipe failed"); goto x_fail; } - if ( libxl_write_exactly(ctx, autopass_fd, vnc_pass, strlen(vnc_pass), - tmpname, "vnc password") ) + if ( libxl_write_exactly(ctx, autopass_fds[1], vnc_pass, strlen(vnc_pass), + "(pipe)", "vnc password") ) goto x_fail; - if ( lseek(autopass_fd, SEEK_SET, 0) ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "rewind %s (autopass) failed", tmpname); + if ( close(autopass_fds[1]) < 0 ) { + autopass_fds[1] = -1; goto x_fail; } + autopass_fds[1] = -1; args[2] = "-autopass"; } - libxl__exec(gc, autopass_fd, -1, -1, args[0], args, NULL); + libxl__exec(gc, autopass_fds[0], -1, -1, args[0], args, NULL); abort(); x_fail: + if ( autopass_fds[0] >= 0 ) close(autopass_fds[0]); + if ( autopass_fds[1] >= 0 ) close(autopass_fds[1]); GC_FREE; return ERROR_FAIL; } -- 1.7.10.4