gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r36839 - libmicrohttpd/src/examples


From: gnunet
Subject: [GNUnet-SVN] r36839 - libmicrohttpd/src/examples
Date: Mon, 18 Jan 2016 22:46:57 +0100

Author: grothoff
Date: 2016-01-18 22:46:56 +0100 (Mon, 18 Jan 2016)
New Revision: 36839

Modified:
   libmicrohttpd/src/examples/demo.c
   libmicrohttpd/src/examples/demo_https.c
   libmicrohttpd/src/examples/fileserver_example.c
Log:
-fixes in code clones()

Modified: libmicrohttpd/src/examples/demo.c
===================================================================
--- libmicrohttpd/src/examples/demo.c   2016-01-18 21:42:33 UTC (rev 36838)
+++ libmicrohttpd/src/examples/demo.c   2016-01-18 21:46:56 UTC (rev 36839)
@@ -693,12 +693,19 @@
       if ( (0 != strcmp (method, MHD_HTTP_METHOD_GET)) &&
            (0 != strcmp (method, MHD_HTTP_METHOD_HEAD)) )
         return MHD_NO;  /* unexpected method (we're not polite...) */
-      if ( (0 == stat (&url[1], &buf)) &&
-          (NULL == strstr (&url[1], "..")) &&
-          ('/' != url[1]))
-       fd = open (&url[1], O_RDONLY);
-      else
-       fd = -1;
+      fd = -1;
+      if ( (NULL == strstr (&url[1], "..")) &&
+          ('/' != url[1]) )
+        {
+          fd = open (&url[1], O_RDONLY);
+          if ( (-1 != fd) &&
+               ( (0 != fstat (fd, &buf)) ||
+                 (! S_ISREG (buf.st_mode)) ) )
+            {
+              (void) close (fd);
+              fd = -1;
+            }
+        }
       if (-1 == fd)
        return MHD_queue_response (connection,
                                   MHD_HTTP_NOT_FOUND,

Modified: libmicrohttpd/src/examples/demo_https.c
===================================================================
--- libmicrohttpd/src/examples/demo_https.c     2016-01-18 21:42:33 UTC (rev 
36838)
+++ libmicrohttpd/src/examples/demo_https.c     2016-01-18 21:46:56 UTC (rev 
36839)
@@ -668,7 +668,7 @@
  * @param upload_data data from upload (PUT/POST)
  * @param upload_data_size number of bytes in "upload_data"
  * @param ptr our context
- * @return MHD_YES on success, MHD_NO to drop connection
+ * @return #MHD_YES on success, #MHD_NO to drop connection
  */
 static int
 generate_page (void *cls,
@@ -694,7 +694,6 @@
       if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
        return MHD_NO;  /* unexpected method (we're not polite...) */
       fd = -1;
-
       if ( (NULL == strstr (&url[1], "..")) &&
           ('/' != url[1]) )
         {

Modified: libmicrohttpd/src/examples/fileserver_example.c
===================================================================
--- libmicrohttpd/src/examples/fileserver_example.c     2016-01-18 21:42:33 UTC 
(rev 36838)
+++ libmicrohttpd/src/examples/fileserver_example.c     2016-01-18 21:46:56 UTC 
(rev 36839)
@@ -63,6 +63,7 @@
   struct MHD_Response *response;
   int ret;
   FILE *file;
+  int fd;
   struct stat buf;
 
   if ( (0 != strcmp (method, MHD_HTTP_METHOD_GET)) &&
@@ -75,10 +76,23 @@
       return MHD_YES;
     }
   *ptr = NULL;                  /* reset when done */
-  if (0 == stat (&url[1], &buf))
-    file = fopen (&url[1], "rb");
-  else
-    file = NULL;
+  file = fopen (&url[1], "rb");
+  if (NULL != file)
+    {
+      fd = fileno (file);
+      if (-1 == fd)
+        {
+          (void) fclose (file);
+          return MHD_NO; /* internal error */
+        }
+      if ( (0 != fstat (fd, &buf)) ||
+           (! S_ISREG (buf.st_mode)) )
+        {
+          /* not a regular file, refuse to serve */
+          fclose (file);
+          file = NULL;
+        }
+    }
   if (NULL == file)
     {
       response = MHD_create_response_from_buffer (strlen (PAGE),




reply via email to

[Prev in Thread] Current Thread [Next in Thread]