[prev in list] [next in list] [prev in thread] [next in thread] 

List:       privoxy-commits
Subject:    [privoxy-commits] current jbsockets.c, 1.49, 1.50 jbsockets.h, 1.13,
From:       noreply () sourceforge ! net
Date:       2008-12-20 14:53:57
Message-ID: E1LE3DJ-0003X8-DE () 23jxhf1 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Update of /cvsroot/ijbswa/current
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv13574

Modified Files:
	jbsockets.c jbsockets.h jcc.c loadcfg.c project.h 
Log Message:
Add config option socket-timeout to control the time
Privoxy waits for data to arrive on a socket. Useful
in case of stale ssh tunnels or when fuzz-testing.


Index: jbsockets.c
===================================================================
RCS file: /cvsroot/ijbswa/current/jbsockets.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- jbsockets.c	10 Nov 2008 17:03:57 -0000	1.49
+++ jbsockets.c	20 Dec 2008 14:53:55 -0000	1.50
@@ -35,6 +35,11 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.50  2008/12/20 14:53:55  fabiankeil
+ *    Add config option socket-timeout to control the time
+ *    Privoxy waits for data to arrive on a socket. Useful
+ *    in case of stale ssh tunnels or when fuzz-testing.
+ *
  *    Revision 1.49  2008/11/10 17:03:57  fabiankeil
  *    Fix a gcc44 warning and remove a now-obsolete cast.
  *
@@ -588,6 +593,46 @@
 
 /*********************************************************************
  *
+ * Function    :  data_is_available
+ *
+ * Description :  Waits for data to arrive on a socket.
+ *
+ * Parameters  :
+ *          1  :  fd = file descriptor of the socket to read
+ *          2  :  seconds_to_wait = number of seconds after which we give up.
+ *
+ * Returns     :  TRUE if data arrived in time,
+ *                FALSE otherwise.
+ *
+ *********************************************************************/
+int data_is_available(jb_socket fd, int seconds_to_wait)
+{
+   fd_set rfds;
+   struct timeval timeout;
+   int n;
+
+   memset(&timeout, 0, sizeof(timeout));
+   timeout.tv_sec = seconds_to_wait;
+
+#ifdef __OS2__
+   /* Copy and pasted from jcc.c ... */
+   memset(&rfds, 0, sizeof(fd_set));
+#else
+   FD_ZERO(&rfds);
+#endif
+   FD_SET(fd, &rfds);
+
+   n = select(fd+1, &rfds, NULL, NULL, &timeout);
+
+   /*
+    * XXX: Do we care about the different error conditions?
+    */
+   return (n == 1);
+}
+
+
+/*********************************************************************
+ *
  * Function    :  close_socket
  *
  * Description :  Closes a TCP/IP socket

Index: jbsockets.h
===================================================================
RCS file: /cvsroot/ijbswa/current/jbsockets.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- jbsockets.h	21 Mar 2008 11:13:59 -0000	1.13
+++ jbsockets.h	20 Dec 2008 14:53:55 -0000	1.14
@@ -37,6 +37,11 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.14  2008/12/20 14:53:55  fabiankeil
+ *    Add config option socket-timeout to control the time
+ *    Privoxy waits for data to arrive on a socket. Useful
+ *    in case of stale ssh tunnels or when fuzz-testing.
+ *
  *    Revision 1.13  2008/03/21 11:13:59  fabiankeil
  *    Only gather host information if it's actually needed.
  *    Also move the code out of accept_connection() so it's less likely
@@ -118,6 +123,7 @@
 extern int write_socket(jb_socket fd, const char *buf, size_t n);
 #endif
 extern int read_socket(jb_socket fd, char *buf, int n);
+extern int data_is_available(jb_socket fd, int seconds_to_wait);
 extern void close_socket(jb_socket fd);
 
 extern int bind_port(const char *hostnam, int portnum, jb_socket *pfd);

Index: jcc.c
===================================================================
RCS file: /cvsroot/ijbswa/current/jcc.c,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -d -r1.213 -r1.214
--- jcc.c	15 Dec 2008 18:45:51 -0000	1.213
+++ jcc.c	20 Dec 2008 14:53:55 -0000	1.214
@@ -33,6 +33,11 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.214  2008/12/20 14:53:55  fabiankeil
+ *    Add config option socket-timeout to control the time
+ *    Privoxy waits for data to arrive on a socket. Useful
+ *    in case of stale ssh tunnels or when fuzz-testing.
+ *
  *    Revision 1.213  2008/12/15 18:45:51  fabiankeil
  *    When logging crunches, log the whole URL, so one can easily
  *    differentiate between vanilla HTTP and CONNECT requests.
@@ -2165,6 +2170,13 @@
 
    do
    {
+      if (!data_is_available(csp->cfd, csp->config->socket_timeout))
+      {
+         log_error(LOG_LEVEL_ERROR,
+            "Stopped waiting for the request line.");
+         return '\0';
+      }
+
       len = read_socket(csp->cfd, buf, sizeof(buf) - 1);
 
       if (len <= 0) return NULL;
@@ -2297,6 +2309,13 @@
           * We didn't receive a complete header
           * line yet, get the rest of it.
           */
+         if (!data_is_available(csp->cfd, csp->config->socket_timeout))
+         {
+            log_error(LOG_LEVEL_ERROR,
+               "Stopped grabbing the client headers.");
+            return JB_ERR_PARSE;
+         }
+
          len = read_socket(csp->cfd, buf, sizeof(buf) - 1);
          if (len <= 0)
          {
@@ -2478,8 +2497,11 @@
 
    /* Skeleton for HTTP response, if we should intercept the request */
    struct http_response *rsp;
+   struct timeval timeout;
 
    memset(buf, 0, sizeof(buf));
+   memset(&timeout, 0, sizeof(timeout));
+   timeout.tv_sec = csp->config->socket_timeout;
 
    http = csp->http;
 
@@ -2720,9 +2742,15 @@
       }
 #endif  /* FEATURE_CONNECTION_KEEP_ALIVE */
 
-      n = select((int)maxfd+1, &rfds, NULL, NULL, NULL);
+      n = select((int)maxfd+1, &rfds, NULL, NULL, &timeout);
 
-      if (n < 0)
+      if (n == 0)
+      {
+         log_error(LOG_LEVEL_ERROR, "Didn't receive data in time.");
+         mark_server_socket_tainted(csp);
+         return;
+      }
+      else if (n < 0)
       {
          log_error(LOG_LEVEL_ERROR, "select() failed!: %E");
          mark_server_socket_tainted(csp);

Index: loadcfg.c
===================================================================
RCS file: /cvsroot/ijbswa/current/loadcfg.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- loadcfg.c	16 Nov 2008 12:43:49 -0000	1.82
+++ loadcfg.c	20 Dec 2008 14:53:55 -0000	1.83
@@ -35,6 +35,11 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.83  2008/12/20 14:53:55  fabiankeil
+ *    Add config option socket-timeout to control the time
+ *    Privoxy waits for data to arrive on a socket. Useful
+ *    in case of stale ssh tunnels or when fuzz-testing.
+ *
  *    Revision 1.82  2008/11/16 12:43:49  fabiankeil
  *    Turn keep-alive support into a runtime feature
  *    that is disabled by setting keep-alive-timeout
@@ -587,6 +592,7 @@
 #define hash_permit_access               3587953268ul /* "permit-access" */
 #define hash_proxy_info_url              3903079059ul /* "proxy-info-url" */
 #define hash_single_threaded             4250084780ul /* "single-threaded" */
+#define hash_socket_timeout              1809001761ul /* "socket-timeout" */
 #define hash_split_large_cgi_forms        671658948ul /* "split-large-cgi-forms" */
 #define hash_suppress_blocklists         1948693308ul /* "suppress-blocklists" */
 #define hash_templdir                      11067889ul /* "templdir" */
@@ -788,6 +794,7 @@
    config->usermanual                = strdup(USER_MANUAL_URL);
    config->proxy_args                = strdup("");
    config->forwarded_connect_retries = 0;
+   config->socket_timeout            = 180;
    config->feature_flags            &= ~RUNTIME_FEATURE_CGI_TOGGLE;
    config->feature_flags            &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS;
    config->feature_flags            &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS;
@@ -1488,6 +1495,25 @@
             continue;
 
 /* *************************************************************************
+ * socket-timeout numer_of_seconds
+ * *************************************************************************/
+         case hash_socket_timeout :
+            if (*arg != '\0')
+            {
+               int socket_timeout = atoi(arg);
+               if (0 < socket_timeout)
+               {
+                  config->socket_timeout = socket_timeout;
+               }
+               else
+               {
+                  log_error(LOG_LEVEL_FATAL,
+                     "Invalid socket-timeout: '%s'", arg);
+               }
+            }
+            continue;
+
+/* *************************************************************************
  * split-large-cgi-forms
  * *************************************************************************/
          case hash_split_large_cgi_forms :

Index: project.h
===================================================================
RCS file: /cvsroot/ijbswa/current/project.h,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- project.h	14 Dec 2008 17:02:54 -0000	1.126
+++ project.h	20 Dec 2008 14:53:55 -0000	1.127
@@ -37,6 +37,11 @@
  *
  * Revisions   :
  *    $Log$
+ *    Revision 1.127  2008/12/20 14:53:55  fabiankeil
+ *    Add config option socket-timeout to control the time
+ *    Privoxy waits for data to arrive on a socket. Useful
+ *    in case of stale ssh tunnels or when fuzz-testing.
+ *
  *    Revision 1.126  2008/12/14 17:02:54  fabiankeil
  *    Fix a cparser warning.
  *
@@ -1791,6 +1796,9 @@
    /** Number of retries in case a forwarded connection attempt fails */
    int         forwarded_connect_retries;
 
+   /* Timeout when waiting on sockets for data to become available. */
+   int socket_timeout;
+
    /** All options from the config file, HTML-formatted. */
    char *proxy_args;
 


------------------------------------------------------------------------------
_______________________________________________
ijbswa-commits mailing list
ijbswa-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ijbswa-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic