]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-05-31 06:24:42 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 31 May 2004 06:24:42 +0000 (06:24 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 31 May 2004 06:24:42 +0000 (06:24 +0000)
fixed symlink security issue with the image driver

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@450 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

drv_Image.c
lcd4linux.conf.sample

index 8b6246af88b2f68e6596d9f5d3085859cee46b24..82f4e9a70abf0fe29c9377cf046ae08ea292c582 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: drv_Image.c,v 1.2 2004/05/29 23:30:20 reinelt Exp $
+/* $Id: drv_Image.c,v 1.3 2004/05/31 06:24:42 reinelt Exp $
  *
  * new style Image (PPM/PNG) Driver for LCD4Linux 
  *
  *
  *
  * $Log: drv_Image.c,v $
+ * Revision 1.3  2004/05/31 06:24:42  reinelt
+ *
+ * fixed symlink security issue with the image driver
+ *
  * Revision 1.2  2004/05/29 23:30:20  reinelt
  *
  * fixed a compiler issue with drv_Image.c (thanks to Frank Stratmann)
@@ -149,7 +153,13 @@ static int drv_IMG_flush_PPM (void)
   snprintf (path, sizeof(path), output, seq++);
   qprintf(tmp, sizeof(tmp), "%s.tmp", path);
   
-  if ((fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644))<0) {
+  // remove the file
+  unlink (tmp);
+
+  // avoid symlink security hole: 
+  // open it with O_EXCL will fail if the file exists. 
+  // This should not happen because we just unlinked it.
+  if ((fd = open(tmp, O_WRONLY | O_CREAT | O_EXCL, 0644))<0) {
     error ("%s: open(%s) failed: %s", Name, tmp, strerror(errno));
     return -1;
   }
@@ -205,7 +215,7 @@ static int drv_IMG_flush_PNG (void)
   static int seq = 0;
   int xsize, ysize, row, col;
   char path[256], tmp[256];
-  FILE *fp;
+  FILE *fp; int fd;
   gdImagePtr im;
   int bg, hg, fg;
   
@@ -244,8 +254,20 @@ static int drv_IMG_flush_PNG (void)
   snprintf (path, sizeof(path), output, seq++);
   qprintf (tmp, sizeof(tmp), "%s.tmp", path);
   
-  if ((fp = fopen(tmp, "w")) == NULL) {
-    error("%s: fopen(%s) failed: %s\n", Name, tmp, strerror(errno));
+  // remove the file
+  unlink (tmp);
+
+  // avoid symlink security hole: 
+  // open it with O_EXCL will fail if the file exists. 
+  // This should not happen because we just unlinked it.
+  if ((fd = open(tmp, O_WRONLY | O_CREAT | O_EXCL, 0644))<0) {
+    error ("%s: open(%s) failed: %s", Name, tmp, strerror(errno));
+    return -1;
+  }
+  
+  if ((fp = fdopen(fd, "w")) == NULL) {
+    error("%s: fdopen(%s) failed: %s\n", Name, tmp, strerror(errno));
+    close (fd);
     return -1;
   }
 
index aaae679027ccb5b74ada3b216b0810b855d23e04..b61807d23c2e288a1d9183a9a6b3091dd079a63a 100644 (file)
@@ -515,14 +515,14 @@ Layout testMySQL {
 #Display 'MI240'
 #Display 'HD44780-20x4'
 #Display 'M50530-24x8'
-Display 'CF631'
+#Display 'CF631'
 #Display 'CF632'
 #Display 'CF633'
 #Display 'Curses'
 #Display 'USBLCD'
 #Display 'T6963-240x64'
 #Display 'XWindow'
-#Display 'Image'
+Display 'Image'
 
 #Layout  'Default'
 #Layout 'L16x2'