Detecting some out-of memory conditions and exiting with a log message.
authorjongfoster <jongfoster@users.sourceforge.net>
Wed, 20 Feb 2002 23:17:23 +0000 (23:17 +0000)
committerjongfoster <jongfoster@users.sourceforge.net>
Wed, 20 Feb 2002 23:17:23 +0000 (23:17 +0000)
jcc.c

diff --git a/jcc.c b/jcc.c
index cee1601..e9df2f3 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.60 2001/12/30 14:07:32 steudten Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.61 2002/01/17 21:01:52 jongfoster Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -33,6 +33,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.60 2001/12/30 14:07:32 steudten Exp $";
  *
  * Revisions   :
  *    $Log: jcc.c,v $
+ *    Revision 1.61  2002/01/17 21:01:52  jongfoster
+ *    Moving all our URL and URL pattern parsing code to urlmatch.c.
+ *
  *    Revision 1.60  2001/12/30 14:07:32  steudten
  *    - Add signal handling (unix)
  *    - Add SIGHUP handler (unix)
@@ -760,10 +763,17 @@ static void chat(struct client_state *csp)
     * Downgrade http version from 1.1 to 1.0 if +downgrade
     * action applies
     */
-   if (!strcmpic(http->ver, "HTTP/1.1") && csp->action->flags & ACTION_DOWNGRADE)
+   if ( (http->ssl == 0)
+     && (!strcmpic(http->ver, "HTTP/1.1"))
+     && (csp->action->flags & ACTION_DOWNGRADE))
    {
       freez(http->ver);
       http->ver = strdup("HTTP/1.0");
+
+      if (http->ver == NULL)
+      {
+         log_error(LOG_LEVEL_FATAL, "Out of memory downgrading HTTP version");
+      }
    }
 
    /*
@@ -774,21 +784,25 @@ static void chat(struct client_state *csp)
    {
       freez(http->cmd);
 
-      http->cmd = strsav(http->cmd, http->gpc);
-      http->cmd = strsav(http->cmd, " ");
+      http->cmd = strdup(http->gpc);
+      string_append(&http->cmd, " ");
 
       if (fwd->forward_host)
       {
-         http->cmd = strsav(http->cmd, http->url);
+         string_append(&http->cmd, http->url);
       }
       else
       {
-         http->cmd = strsav(http->cmd, http->path);
+         string_append(&http->cmd, http->path);
       }
 
-      http->cmd = strsav(http->cmd, " ");
-      http->cmd = strsav(http->cmd, http->ver);
+      string_append(&http->cmd, " ");
+      string_append(&http->cmd, http->ver);
 
+      if (http->cmd == NULL)
+      {
+         log_error(LOG_LEVEL_FATAL, "Out of memory rewiting SSL command");
+      }
    }
    enlist(csp->headers, http->cmd);
 
@@ -941,6 +955,12 @@ static void chat(struct client_state *csp)
    log_error(LOG_LEVEL_CONNECT, "OK");
 
    hdr = sed(client_patterns, add_client_headers, csp);
+   if (hdr == NULL)\r
+   {\r
+      /* FIXME Should handle error properly */\r
+      log_error(LOG_LEVEL_FATAL, "Out of memory parsing client header");\r
+   }\r
+\r
    list_remove_all(csp->headers);
 
    if (fwd->forward_host || (http->ssl == 0))
@@ -1129,6 +1149,12 @@ static void chat(struct client_state *csp)
                   }
 
                   hdr = sed(server_patterns, add_server_headers, csp);
+                  if (hdr == NULL)\r
+                  {\r
+                     /* FIXME Should handle error properly */\r
+                     log_error(LOG_LEVEL_FATAL, "Out of memory parsing server header");\r
+                  }\r
+\r
                   n = strlen(hdr);
 
                   if ((write_socket(csp->cfd, hdr, n) != n)
@@ -1183,6 +1209,12 @@ static void chat(struct client_state *csp)
                   log_error(LOG_LEVEL_ERROR, "Buffer size limit reached! Flushing and stepping back.");
 
                   hdr = sed(server_patterns, add_server_headers, csp);
+                  if (hdr == NULL)\r
+                  {\r
+                     /* FIXME Should handle error properly */\r
+                     log_error(LOG_LEVEL_FATAL, "Out of memory parsing server header");\r
+                  }\r
+\r
                   n   = strlen(hdr);
                   byte_count += n;
 
@@ -1271,6 +1303,12 @@ static void chat(struct client_state *csp)
              */
 
             hdr = sed(server_patterns, add_server_headers, csp);
+            if (hdr == NULL)\r
+            {\r
+               /* FIXME Should handle error properly */\r
+               log_error(LOG_LEVEL_FATAL, "Out of memory parsing server header");\r
+            }\r
+\r
             n   = strlen(hdr);
 
             /* write the server's (modified) header to