[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 11/13] libxl: use pipe instead of temporary file for VNC viewer --autopass
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 <mattd@xxxxxxxxxxx> --- 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 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |