From: Ben Pfaff Date: Wed, 16 Jun 2010 05:19:17 +0000 (-0700) Subject: psppire: Fix insecure temporary file creation in clipboard_get_cb(). X-Git-Tag: v0.7.6~361 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4eac86bdd50377578553ca2aa2eb87199dbb0aa1;p=pspp-builds.git psppire: Fix insecure temporary file creation in clipboard_get_cb(). --- diff --git a/src/ui/gui/psppire-output-window.c b/src/ui/gui/psppire-output-window.c index b2ea1103..0dacd134 100644 --- a/src/ui/gui/psppire-output-window.c +++ b/src/ui/gui/psppire-output-window.c @@ -16,33 +16,31 @@ #include -#include -#include -#include "helper.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include - -#include "help-menu.h" - -#include "psppire-output-window.h" - - -#include "xalloc.h" - -#include #include +#include #include +#include "libpspp/cast.h" +#include "libpspp/message.h" +#include "libpspp/string-map.h" +#include "output/cairo.h" +#include "output/chart-item.h" +#include "output/driver-provider.h" +#include "output/output-item.h" +#include "output/tab.h" +#include "output/table-item.h" +#include "output/text-item.h" +#include "ui/gui/help-menu.h" +#include "ui/gui/helper.h" +#include "ui/gui/psppire-output-window.h" + +#include "gl/error.h" +#include "gl/tmpdir.h" +#include "gl/xalloc.h" + #include #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -801,7 +799,7 @@ clipboard_get_cb (GtkClipboard *clipboard, gsize length; gchar *text = NULL; struct output_driver *driver = NULL; - char *filename = NULL; + char dirname[PATH_MAX], *filename; struct string_map options; GtkTreeSelection *sel = gtk_tree_view_get_selection (window->overview); @@ -813,8 +811,15 @@ clipboard_get_cb (GtkClipboard *clipboard, if ( n == NULL) return; + if (path_search (dirname, sizeof dirname, NULL, NULL, true) + || mkdtemp (dirname) == NULL) + { + error (0, errno, _("failed to create temporary directory")); + return; + } + filename = xasprintf ("%s/clip.tmp", dirname); + string_map_init (&options); - filename = tempnam (NULL, NULL); string_map_insert (&options, "output-file", filename); switch (info) @@ -884,6 +889,7 @@ clipboard_get_cb (GtkClipboard *clipboard, unlink (filename); free (filename); + rmdir (dirname); g_list_free (rows); }