improve handling of @@line continuations
[privoxy.git] / loaders.c
index f6b1628..7683fa5 100644 (file)
--- a/loaders.c
+++ b/loaders.c
@@ -1,4 +1,3 @@
-const char loaders_rcs[] = "$Id: loaders.c,v 1.100 2015/01/24 16:40:21 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loaders.c,v $
@@ -63,8 +62,6 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.100 2015/01/24 16:40:21 fabiankei
 #include "urlmatch.h"
 #include "encode.h"
 
-const char loaders_h_rcs[] = LOADERS_H_VERSION;
-
 /*
  * Currently active files.
  * These are also entered in the main linked list of files.
@@ -74,13 +71,51 @@ const char loaders_h_rcs[] = LOADERS_H_VERSION;
 static struct file_list *current_trustfile      = NULL;
 #endif /* def FEATURE_TRUST */
 
+#ifndef FUZZ
 static int load_one_re_filterfile(struct client_state *csp, int fileid);
+#endif
 
 static struct file_list *current_re_filterfile[MAX_AF_FILES]  = {
    NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL
 };
 
+/*********************************************************************
+ *
+ * Function    :  free_csp_resources
+ *
+ * Description :  Frees memory referenced by the csp that isn't
+ *                shared with other csps.
+ *
+ * Parameters  :
+ *          1  :  csp = Current client state (buffers, headers, etc...)
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+void free_csp_resources(struct client_state *csp)
+{
+   freez(csp->ip_addr_str);
+#ifdef FEATURE_CLIENT_TAGS
+   freez(csp->client_address);
+#endif
+   freez(csp->listen_addr_str);
+   freez(csp->client_iob->buf);
+   freez(csp->iob->buf);
+   freez(csp->error_message);
+
+   if (csp->action->flags & ACTION_FORWARD_OVERRIDE &&
+      NULL != csp->fwd)
+   {
+      unload_forward_spec(csp->fwd);
+   }
+   free_http_request(csp->http);
+
+   destroy_list(csp->headers);
+   destroy_list(csp->tags);
+
+   free_current_action(csp->action);
+}
 
 /*********************************************************************
  *
@@ -181,23 +216,6 @@ unsigned int sweep(void)
       {
          last_active->next = client_list->next;
 
-         freez(csp->ip_addr_str);
-         freez(csp->client_iob->buf);
-         freez(csp->iob->buf);
-         freez(csp->error_message);
-
-         if (csp->action->flags & ACTION_FORWARD_OVERRIDE &&
-             NULL != csp->fwd)
-         {
-            unload_forward_spec(csp->fwd);
-         }
-         free_http_request(csp->http);
-
-         destroy_list(csp->headers);
-         destroy_list(csp->tags);
-
-         free_current_action(csp->action);
-
 #ifdef FEATURE_STATISTICS
          urls_read++;
          if (csp->flags & CSP_FLAG_REJECTED)
@@ -289,15 +307,9 @@ int check_file_changed(const struct file_list * current,
    }
 
    fs = zalloc_or_die(sizeof(struct file_list));
-   fs->filename = strdup(filename);
+   fs->filename = strdup_or_die(filename);
    fs->lastmodified = statbuf->st_mtime;
 
-   if (fs->filename == NULL)
-   {
-      /* Out of memory error */
-      freez (fs);
-      return 1;
-   }
    *newfl = fs;
    return 1;
 }
@@ -357,6 +369,7 @@ jb_err simple_read_line(FILE *fp, char **dest, int *newline)
    for (;;)
    {
       ch = getc(fp);
+
       if (ch == EOF)
       {
          if (len > 0)
@@ -413,6 +426,7 @@ jb_err simple_read_line(FILE *fp, char **dest, int *newline)
       }
       else if (ch == 0)
       {
+         /* XXX: Why do we allow this anyway? */
          *p = '\0';
          *dest = buf;
          return JB_ERR_OK;
@@ -530,30 +544,15 @@ jb_err edit_read_line(FILE *fp,
 
    if (raw_out)
    {
-      raw = strdup("");
-      if (NULL == raw)
-      {
-         return JB_ERR_MEMORY;
-      }
+      raw = strdup_or_die("");
    }
    if (prefix_out)
    {
-      prefix = strdup("");
-      if (NULL == prefix)
-      {
-         freez(raw);
-         return JB_ERR_MEMORY;
-      }
+      prefix = strdup_or_die("");
    }
    if (data_out)
    {
-      data = strdup("");
-      if (NULL == data)
-      {
-         freez(raw);
-         freez(prefix);
-         return JB_ERR_MEMORY;
-      }
+      data = strdup_or_die("");
    }
 
    /* Main loop.  Loop while we need more data & it's not EOF. */
@@ -645,15 +644,12 @@ jb_err edit_read_line(FILE *fp,
       if (*linestart)
       {
          is_empty = 0;
-         if (data)
+         if (string_append(&data, linestart))
          {
-            if (string_append(&data, linestart))
-            {
-               freez(raw);
-               freez(prefix);
-               free(linebuf);
-               return JB_ERR_MEMORY;
-            }
+            freez(raw);
+            freez(prefix);
+            free(linebuf);
+            return JB_ERR_MEMORY;
          }
       }
 
@@ -1195,15 +1191,16 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
             new_bl->description = html_encode(chomp(new_bl->description));
             if (NULL == new_bl->description)
             {
-               new_bl->description = strdup("Out of memory while encoding this filter's description to HTML");
+               new_bl->description = strdup_or_die("Out of memory while "
+                  "encoding filter description to HTML");
             }
          }
          else
          {
-            new_bl->description = strdup("No description available for this filter");
+            new_bl->description = strdup_or_die("No description available");
          }
 
-         new_bl->name = strdup(chomp(new_bl->name));
+         new_bl->name = strdup_or_die(chomp(new_bl->name));
 
          /*
           * If this is the first filter block, chain it