Wrapping all *_r functions (the non-_r versions of them) with mutex semaphores for...
authorDavid Schmidt <david__schmidt@users.sourceforge.net>
Fri, 7 Mar 2003 03:41:05 +0000 (03:41 +0000)
committerDavid Schmidt <david__schmidt@users.sourceforge.net>
Fri, 7 Mar 2003 03:41:05 +0000 (03:41 +0000)
cgi.c
configure.in
errlog.c
jbsockets.c
jcc.c
jcc.h
parsers.c

diff --git a/cgi.c b/cgi.c
index d276944..77ed1db 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.70.2.2 2002/11/12 16:20:37 oes Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.70.2.3 2002/11/28 18:14:32 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/Attic/cgi.c,v $
@@ -38,6 +38,20 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.70.2.2 2002/11/12 16:20:37 oes Exp $";
  *
  * Revisions   :
  *    $Log: cgi.c,v $
+ *    Revision 1.70.2.3  2002/11/28 18:14:32  oes
+ *    Disable access to critical CGIs via untrusted referrers.
+ *    This prevents users from being tricked by malicious websites
+ *    into making unintentional configuration changes:
+ *
+ *     - Added flag to each cgi_dispatcher that allows or denies
+ *       external linking
+ *     - Introduced proviorical function that greps for the
+ *       referrer header before regular header parsing happens
+ *     - Added safety check to dispatch_known_cgi. CGI is called
+ *       if (cgi harmless || no referrer || we are referrer).
+ *       Else a) toggle calls are modified not to change status and
+ *       b) all other calls are denied.
+ *
  *    Revision 1.70.2.2  2002/11/12 16:20:37  oes
  *    Added missing #ifdef FEATURE_TOGGLE around g_bToggleIJB; fixes bug #636651
  *
@@ -421,7 +435,11 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.70.2.2 2002/11/12 16:20:37 oes Exp $";
 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
 #include "loadcfg.h"
 /* loadcfg.h is for g_bToggleIJB only */
-
+#ifdef FEATURE_PTHREAD
+#include <pthread.h>
+#include "jcc.h"
+/* jcc.h is for mutex semaphore globals only */
+#endif /* def FEATURE_PTHREAD */
 const char cgi_h_rcs[] = CGI_H_VERSION;
 
 /*
@@ -1503,7 +1521,11 @@ void get_http_time(int time_offset, char *buf)
 
    /* get and save the gmt */
    {
-#ifdef HAVE_GMTIME_R
+#ifdef OSX_DARWIN
+      pthread_mutex_lock(&gmtime_mutex);
+      t = gmtime(&current_time);
+      pthread_mutex_unlock(&gmtime_mutex);
+#elif HAVE_GMTIME_R
       struct tm dummy;
       t = gmtime_r(&current_time, &dummy);
 #else
index 212c286..8e01d3d 100644 (file)
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 dnl 
-dnl $Id: configure.in,v 1.68.2.10 2003/01/08 16:39:41 oes Exp $
+dnl $Id: configure.in,v 1.68.2.11 2003/03/06 15:22:37 oes Exp $
 dnl 
 dnl Written by and Copyright (C) 2001, 2002 the SourceForge
 dnl Privoxy team. http://www.privoxy.org/
@@ -28,6 +28,9 @@ dnl or write to the Free Software Foundation, Inc., 59
 dnl Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 dnl 
 dnl $Log: configure.in,v $
+dnl Revision 1.68.2.11  2003/03/06 15:22:37  oes
+dnl Fixed minor shell syntax bug
+dnl
 dnl Revision 1.68.2.10  2003/01/08 16:39:41  oes
 dnl Changing default to exclude FEATURE_IMAGE_DETECT_MSIE because of problem reports with recent IEs
 dnl
@@ -403,7 +406,7 @@ dnl =================================================================
 dnl AutoConf Initialization
 dnl =================================================================
 
-AC_REVISION($Revision: 1.68.2.10 $)
+AC_REVISION($Revision: 1.68.2.11 $)
 AC_INIT(jcc.c)
 
 if test ! -f config.h.in; then
@@ -988,7 +991,7 @@ dnl Mac OSX specific
 dnl =================================================================
     
 case "$host" in
-*-apple-darwin*) SPECIAL_CFLAGS="-Dunix"
+*-apple-darwin*) SPECIAL_CFLAGS="-Dunix -DOSX_DARWIN"
 ;;  
 esac
 
index 4a4de4f..3f4174f 100644 (file)
--- a/errlog.c
+++ b/errlog.c
@@ -1,4 +1,4 @@
-const char errlog_rcs[] = "$Id: errlog.c,v 1.40.2.1 2002/09/25 12:47:42 oes Exp $";
+const char errlog_rcs[] = "$Id: errlog.c,v 1.40.2.2 2002/09/28 00:30:57 david__schmidt Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/Attic/errlog.c,v $
@@ -33,6 +33,11 @@ const char errlog_rcs[] = "$Id: errlog.c,v 1.40.2.1 2002/09/25 12:47:42 oes Exp
  *
  * Revisions   :
  *    $Log: errlog.c,v $
+ *    Revision 1.40.2.2  2002/09/28 00:30:57  david__schmidt
+ *    Update error logging to give sane values for thread IDs on Mach kernels.
+ *    It's still a hack, but at least it looks farily normal.  We print the
+ *    absolute value of the first 4 bytes of the pthread_t modded with 1000.
+ *
  *    Revision 1.40.2.1  2002/09/25 12:47:42  oes
  *    Make log_error safe against NULL string arguments
  *
@@ -459,6 +464,10 @@ void log_error(int loglevel, char *fmt, ...)
        time (&now);
 #ifdef HAVE_LOCALTIME_R
        tm_now = *localtime_r(&now, &tm_now);
+#elif OSX_DARWIN
+       pthread_mutex_lock(&localtime_mutex);
+       tm_now = *localtime (&now); 
+       pthread_mutex_unlock(&localtime_mutex);
 #else
        tm_now = *localtime (&now); 
 #endif
@@ -722,11 +731,19 @@ void log_error(int loglevel, char *fmt, ...)
                time (&now); 
 #ifdef HAVE_GMTIME_R
                gmt = *gmtime_r(&now, &gmt);
+#elif OSX_DARWIN
+               pthread_mutex_lock(&gmtime_mutex);
+               gmt = *gmtime(&now);
+               pthread_mutex_unlock(&gmtime_mutex);
 #else
                gmt = *gmtime(&now);
 #endif
 #ifdef HAVE_LOCALTIME_R
                tm_now = localtime_r(&now, &dummy);
+#elif OSX_DARWIN
+               pthread_mutex_lock(&localtime_mutex);
+               tm_now = localtime (&now); 
+               pthread_mutex_unlock(&localtime_mutex);
 #else
                tm_now = localtime (&now); 
 #endif
index 758e5cf..8efb642 100644 (file)
@@ -1,4 +1,4 @@
-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.35.2.1 2002/05/26 23:41:27 joergs Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.35.2.2 2002/11/20 14:37:24 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/Attic/jbsockets.c,v $
@@ -35,6 +35,10 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.35.2.1 2002/05/26 23:41:27 jo
  *
  * Revisions   :
  *    $Log: jbsockets.c,v $
+ *    Revision 1.35.2.2  2002/11/20 14:37:24  oes
+ *    Fixed Win32 error logging in bind_port.
+ *    Thanks to Oliver Stoeneberg for the hint.
+ *
  *    Revision 1.35.2.1  2002/05/26 23:41:27  joergs
  *    AmigaOS: Fixed wrong type of len in write_socket()
  *
@@ -230,6 +234,12 @@ const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.35.2.1 2002/05/26 23:41:27 jo
 
 #endif
 
+#ifdef OSX_DARWIN
+#include <pthread.h>
+#include "jcc.h"
+/* jcc.h is for mutex semaphores only */
+#endif /* def OSX_DARWIN */
+
 #include "project.h"
 #include "jbsockets.h"
 #include "filters.h"
@@ -710,6 +720,11 @@ int accept_connection(struct client_state * csp, jb_socket fd)
       {
          host = NULL;
       }
+#elif defined(OSX_DARWIN)
+      pthread_mutex_lock(&gethostbyaddr_mutex);
+      host = gethostbyaddr((const char *)&server.sin_addr, 
+                           sizeof(server.sin_addr), AF_INET);
+      pthread_mutex_unlock(&gethostbyaddr_mutex);
 #else
       host = gethostbyaddr((const char *)&server.sin_addr, 
                            sizeof(server.sin_addr), AF_INET);
@@ -784,6 +799,10 @@ unsigned long resolve_hostname_to_ip(const char *host)
       {
          hostp = NULL;
       }
+#elif OSX_DARWIN
+      pthread_mutex_lock(&gethostbyname_mutex);
+      hostp = gethostbyname(host);
+      pthread_mutex_unlock(&gethostbyname_mutex);
 #else
       hostp = gethostbyname(host);
 #endif /* def HAVE_GETHOSTBYNAME_R_(6|5|3)_ARGS */
diff --git a/jcc.c b/jcc.c
index cb81afe..8628084 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.92.2.2 2002/11/20 14:37:47 oes Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.92.2.3 2003/02/28 12:53:06 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/Attic/jcc.c,v $
@@ -33,6 +33,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.92.2.2 2002/11/20 14:37:47 oes Exp $";
  *
  * Revisions   :
  *    $Log: jcc.c,v $
+ *    Revision 1.92.2.3  2003/02/28 12:53:06  oes
+ *    Fixed two mostly harmless mem leaks
+ *
  *    Revision 1.92.2.2  2002/11/20 14:37:47  oes
  *    Fix: Head of global clients list now initialized to NULL
  *
@@ -667,6 +670,16 @@ static int32 server_thread(void *data);
 #define sleep(N)  DosSleep(((N) * 100))
 #endif
 
+#ifdef OSX_DARWIN
+/*
+ * Hit OSX over the head with a hammer.  Protect all *_r functions.
+ */
+pthread_mutex_t gmtime_mutex;
+pthread_mutex_t localtime_mutex;
+pthread_mutex_t gethostbyaddr_mutex;
+pthread_mutex_t gethostbyname_mutex;
+#endif /* def OSX_DARWIN */
+
 #if defined(unix) || defined(__EMX__)
 const char *basedir;
 const char *pidfile = NULL;
@@ -1846,6 +1859,16 @@ int main(int argc, const char *argv[])
    InitWin32();
 #endif
 
+#ifdef OSX_DARWIN
+   /*
+    * Prepare global mutex semaphores
+    */
+   pthread_mutex_init(&gmtime_mutex,0);
+   pthread_mutex_init(&localtime_mutex,0);
+   pthread_mutex_init(&gethostbyaddr_mutex,0);
+   pthread_mutex_init(&gethostbyname_mutex,0);
+#endif /* def OSX_DARWIN */
+
    /*
     * Unix signal handling
     *
diff --git a/jcc.h b/jcc.h
index 1778f1e..852d511 100644 (file)
--- a/jcc.h
+++ b/jcc.h
@@ -1,9 +1,9 @@
 #ifndef JCC_H_INCLUDED
 #define JCC_H_INCLUDED
-#define JCC_H_VERSION "$Id: jcc.h,v 1.11 2002/03/24 13:25:43 swa Exp $"
+#define JCC_H_VERSION "$Id: jcc.h,v 1.12 2002/03/26 22:29:55 swa Exp $"
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa/current/jcc.h,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/Attic/jcc.h,v $
  *
  * Purpose     :  Main file.  Contains main() method, main loop, and 
  *                the main connection-handling function.
@@ -35,6 +35,9 @@
  *
  * Revisions   :
  *    $Log: jcc.h,v $
+ *    Revision 1.12  2002/03/26 22:29:55  swa
+ *    we have a new homepage!
+ *
  *    Revision 1.11  2002/03/24 13:25:43  swa
  *    name change related issues
  *
@@ -115,6 +118,13 @@ extern int no_daemon;
 extern int g_terminate;
 #endif
 
+#ifdef OSX_DARWIN
+extern pthread_mutex_t gmtime_mutex;
+extern pthread_mutex_t localtime_mutex;
+extern pthread_mutex_t gethostbyaddr_mutex;
+extern pthread_mutex_t gethostbyname_mutex;
+#endif /* def OSX_DARWIN */
+
 /* Functions */
 
 #ifdef __MINGW32__
index bfea571..ea8d42f 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.56.2.2 2002/09/25 14:59:53 oes Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.56.2.3 2002/11/10 04:20:02 hal9 Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/Attic/parsers.c,v $
@@ -40,6 +40,9 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.56.2.2 2002/09/25 14:59:53 oes Ex
  *
  * Revisions   :
  *    $Log: parsers.c,v $
+ *    Revision 1.56.2.3  2002/11/10 04:20:02  hal9
+ *    Fix typo: supressed -> suppressed
+ *
  *    Revision 1.56.2.2  2002/09/25 14:59:53  oes
  *    Improved cookie logging
  *
@@ -416,6 +419,11 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.56.2.2 2002/09/25 14:59:53 oes Ex
 #include <unistd.h>
 #endif
 
+#ifdef OSX_DARWIN
+#include <pthread.h>
+#include "jcc.h"
+/* jcc.h is for mutex semapores only */
+#endif /* def OSX_DARWIN */
 #include "project.h"
 #include "list.h"
 #include "parsers.h"
@@ -1775,6 +1783,10 @@ jb_err server_set_cookie(struct client_state *csp, char **header)
       time (&now); 
 #ifdef HAVE_LOCALTIME_R
       tm_now = *localtime_r(&now, &tm_now);
+#elif OSX_DARWIN
+      pthread_mutex_lock(&localtime_mutex);
+      tm_now = *localtime (&now); 
+      pthread_mutex_unlock(&localtime_mutex);
 #else
       tm_now = *localtime (&now); 
 #endif