diff gtk3/dw.c @ 2201:ae6626a4331f

GTK: Same change from tmpnam() to mkstemp() for GTK2 plus extra safety checks on both GTK2 and GTK3.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 27 Oct 2020 00:52:13 +0000
parents 319eeecb411e
children c677d728e143
line wrap: on
line diff
--- a/gtk3/dw.c	Tue Oct 27 00:15:46 2020 +0000
+++ b/gtk3/dw.c	Tue Oct 27 00:52:13 2020 +0000
@@ -4554,14 +4554,15 @@
        * of the data to the file
        */
       char template[] = "/tmp/dwpixmapXXXXXX";
-      int fd = mkstemp(template);
-
-      if(fd)
-      {
-         write(fd, data, len);
+      int written = -1, fd = mkstemp(template);
+
+      if(fd != -1)
+      {
+         written = write(fd, data, len);
          close(fd);
       }
-      else
+      /* Bail if we couldn't write full file */
+      if(fd == -1 || written != len)
       {
          DW_MUTEX_UNLOCK;
          return;
@@ -6026,7 +6027,7 @@
  */
 HICN API dw_icon_load_from_data(const char *data, int len)
 {
-   int fd, _locked_by_me = FALSE;
+   int fd, written = -1, _locked_by_me = FALSE;
    char template[] = "/tmp/dwiconXXXXXX";
    HICN ret = 0;
 
@@ -6034,12 +6035,13 @@
     * A real hack; create a temporary file and write the contents
     * of the data to the file
     */
-   if((fd = mkstemp(template)))
-   {
-      write(fd, data, len);
+   if((fd = mkstemp(template)) != -1)
+   {
+      written = write(fd, data, len);
       close(fd);
    }
-   else
+   /* Bail if we couldn't write full file */
+   if(fd == -1 || written != len)
       return 0;
    DW_MUTEX_LOCK;
    ret = _icon_resize(gdk_pixbuf_new_from_file(template, NULL));
@@ -7837,7 +7839,7 @@
  */
 HPIXMAP dw_pixmap_new_from_data(HWND handle, const char *data, int len)
 {
-   int fd, _locked_by_me = FALSE;
+   int fd, written = -1, _locked_by_me = FALSE;
    HPIXMAP pixmap;
    char template[] = "/tmp/dwpixmapXXXXXX";
 
@@ -7849,12 +7851,13 @@
     * A real hack; create a temporary file and write the contents
     * of the data to the file
     */
-   if((fd = mkstemp(template)))
-   {
-      write(fd, data, len);
+   if((fd = mkstemp(template)) != -1)
+   {
+      written = write(fd, data, len);
       close(fd);
    }
-   else
+   /* Bail if we couldn't write full file */
+   if(fd == -1 || written != len)
    {
       DW_MUTEX_UNLOCK;
       return 0;