Don't enforce a logical line length limit in read_config_line()
authorFabian Keil <fk@fabiankeil.de>
Thu, 3 Mar 2011 14:38:36 +0000 (14:38 +0000)
committerFabian Keil <fk@fabiankeil.de>
Thu, 3 Mar 2011 14:38:36 +0000 (14:38 +0000)
It means the caller has to free the buffer, but we can live with that.

actions.c
loadcfg.c
loaders.c
loaders.h

index 11c5f75..5b32114 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -1,4 +1,4 @@
-const char actions_rcs[] = "$Id: actions.c,v 1.61 2011/01/09 12:00:19 fabiankeil Exp $";
+const char actions_rcs[] = "$Id: actions.c,v 1.62 2011/02/14 16:01:20 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/actions.c,v $
@@ -1066,7 +1066,7 @@ static int load_one_actions_file(struct client_state *csp, int fileid)
    FILE *fp;
    struct url_actions *last_perm;
    struct url_actions *perm;
-   char  buf[BUFFER_SIZE];
+   char  *buf;
    struct file_list *fs;
    struct action_spec * cur_action = NULL;
    int cur_action_used = 0;
@@ -1105,7 +1105,7 @@ static int load_one_actions_file(struct client_state *csp, int fileid)
 
    log_error(LOG_LEVEL_INFO, "Loading actions file: %s", csp->config->actions_file[fileid]);
 
-   while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
+   while (read_config_line(fp, &linenum, &buf) != NULL)
    {
       if (*buf == '{')
       {
@@ -1457,6 +1457,7 @@ static int load_one_actions_file(struct client_state *csp, int fileid)
             csp->config->actions_file[fileid], mode);
          return 1; /* never get here */
       }
+      freez(buf);
    }
 
    fclose(fp);
index ff90b07..899e430 100644 (file)
--- a/loadcfg.c
+++ b/loadcfg.c
@@ -1,4 +1,4 @@
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.110 2010/07/21 14:29:59 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.111 2010/08/14 23:28:52 ler762 Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
@@ -292,7 +292,7 @@ void unload_current_config_file(void)
  *********************************************************************/
 struct configuration_spec * load_config(void)
 {
-   char buf[BUFFER_SIZE];
+   char *buf = NULL;
    char *p, *q;
    FILE *configfp = NULL;
    struct configuration_spec * config = NULL;
@@ -373,7 +373,7 @@ struct configuration_spec * load_config(void)
       /* Never get here - LOG_LEVEL_FATAL causes program exit */
    }
 
-   while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL)
+   while (read_config_line(configfp, &linenum, &buf) != NULL)
    {
       char cmd[BUFFER_SIZE];
       char arg[BUFFER_SIZE];
@@ -404,11 +404,15 @@ struct configuration_spec * load_config(void)
       }
 
       /* Copy the argument into arg */
-      strlcpy(arg, p, sizeof(arg));
+      if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg))
+      {
+         log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf);
+      }
 
       /* Should never happen, but check this anyway */
       if (*cmd == '\0')
       {
+         freez(buf);
          continue;
       }
 
@@ -1339,7 +1343,7 @@ struct configuration_spec * load_config(void)
 
       /* Save the argument for the show-status page. */
       savearg(cmd, arg, config);
-
+      freez(buf);
    } /* end while ( read_config_line(...) ) */
 
    fclose(configfp);
index 47dc61d..a239d5f 100644 (file)
--- a/loaders.c
+++ b/loaders.c
@@ -1,4 +1,4 @@
-const char loaders_rcs[] = "$Id: loaders.c,v 1.79 2011/01/14 19:47:16 fabiankeil Exp $";
+const char loaders_rcs[] = "$Id: loaders.c,v 1.80 2011/01/22 12:30:22 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loaders.c,v $
@@ -737,41 +737,27 @@ jb_err edit_read_line(FILE *fp,
  *                and respects escaping of newline and comment char.
  *
  * Parameters  :
- *          1  :  buf = Buffer to use.
- *          2  :  buflen = Size of buffer in bytes.
- *          3  :  fp = File to read from
- *          4  :  linenum = linenumber in file
+ *          1  :  fp = File to read from
+ *          2  :  linenum = linenumber in file
+ *          3  :  buf = Pointer to a pointer to set to the data buffer.
  *
  * Returns     :  NULL on EOF or error
  *                Otherwise, returns buf.
  *
  *********************************************************************/
-char *read_config_line(char *buf, size_t buflen, FILE *fp, unsigned long *linenum)
+char *read_config_line(FILE *fp, unsigned long *linenum, char **buf)
 {
    jb_err err;
-   char *buf2 = NULL;
-   err = edit_read_line(fp, NULL, NULL, &buf2, NULL, linenum);
+   err = edit_read_line(fp, NULL, NULL, buf, NULL, linenum);
    if (err)
    {
       if (err == JB_ERR_MEMORY)
       {
          log_error(LOG_LEVEL_FATAL, "Out of memory loading a config file");
       }
-      return NULL;
-   }
-   else
-   {
-      assert(buf2);
-      if (strlen(buf2) + 1U > buflen)
-      {
-         log_error(LOG_LEVEL_FATAL,
-            "Max line limit reached. Linenumber: %u. Length: %u. Max length: %u.",
-            *linenum, strlen(buf2), buflen-1);
-      }
-      strlcpy(buf, buf2, buflen);
-      free(buf2);
-      return buf;
+      *buf = NULL;
    }
+   return *buf;
 }
 
 
@@ -849,7 +835,7 @@ int load_trustfile(struct client_state *csp)
    struct block_spec *b, *bl;
    struct url_spec **tl;
 
-   char  buf[BUFFER_SIZE], *p, *q;
+   char *buf = NULL;
    int reject, trusted;
    struct file_list *fs;
    unsigned long linenum = 0;
@@ -880,7 +866,7 @@ int load_trustfile(struct client_state *csp)
 
    tl = csp->config->trust_list;
 
-   while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
+   while (read_config_line(fp, &linenum, &buf) != NULL)
    {
       trusted = 0;
       reject  = 1;
@@ -893,6 +879,9 @@ int load_trustfile(struct client_state *csp)
 
       if (*buf == '~')
       {
+         char *p;
+         char *q;
+
          reject = 0;
          p = buf;
          q = p+1;
@@ -905,6 +894,7 @@ int load_trustfile(struct client_state *csp)
       /* skip blank lines */
       if (*buf == '\0')
       {
+         freez(buf);
          continue;
       }
 
@@ -938,6 +928,7 @@ int load_trustfile(struct client_state *csp)
             *tl++ = b->url;
          }
       }
+      freez(buf);
    }
 
    if(trusted_referrers >= MAX_TRUSTED_REFERRERS) 
@@ -969,12 +960,12 @@ int load_trustfile(struct client_state *csp)
    {
       csp->tlist = fs;
    }
-
    return(0);
 
 load_trustfile_error:
    log_error(LOG_LEVEL_FATAL, "can't load trustfile '%s': %E",
-             csp->config->trustfile);
+      csp->config->trustfile);
+   freez(buf);
    return(-1);
 
 }
@@ -1131,7 +1122,7 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
    struct re_filterfile_spec *new_bl, *bl = NULL;
    struct file_list *fs;
 
-   char  buf[BUFFER_SIZE];
+   char *buf = NULL;
    int error;
    unsigned long linenum = 0;
    pcrs_job *dummy, *lastjob = NULL;
@@ -1165,7 +1156,7 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
    /* 
     * Read line by line
     */
-   while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL)
+   while (read_config_line(fp, &linenum, &buf) != NULL)
    {
       int new_filter = NO_NEW_FILTER;
 
@@ -1249,6 +1240,7 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
 
          log_error(LOG_LEVEL_RE_FILTER, "Reading in filter \"%s\" (\"%s\")", bl->name, bl->description);
 
+         freez(buf);
          continue;
       }
 
@@ -1280,6 +1272,7 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
             bl->dynamic = 1;
             log_error(LOG_LEVEL_RE_FILTER,
                "Adding dynamic re_filter job \'%s\' to filter %s succeeded.", buf, bl->name);
+            freez(buf);
             continue;             
          }
          else if (bl->dynamic)
@@ -1291,6 +1284,7 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
              */
             log_error(LOG_LEVEL_RE_FILTER,
                "Adding static re_filter job \'%s\' to dynamic filter %s succeeded.", buf, bl->name);
+            freez(buf);
             continue;
          }
 
@@ -1298,6 +1292,7 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
          {
             log_error(LOG_LEVEL_ERROR,
                "Adding re_filter job \'%s\' to filter %s failed with error %d.", buf, bl->name, error);
+            freez(buf);
             continue;
          }
          else
@@ -1319,6 +1314,7 @@ int load_one_re_filterfile(struct client_state *csp, int fileid)
          log_error(LOG_LEVEL_ERROR, "Ignoring job %s outside filter block in %s, line %d",
             buf, csp->config->re_filterfile[fileid], linenum);
       }
+      freez(buf);
    }
 
    fclose(fp);
index 1951b1d..4e7e465 100644 (file)
--- a/loaders.h
+++ b/loaders.h
@@ -1,6 +1,6 @@
 #ifndef LOADERS_H_INCLUDED
 #define LOADERS_H_INCLUDED
-#define LOADERS_H_VERSION "$Id: loaders.h,v 1.25 2009/05/16 13:27:20 fabiankeil Exp $"
+#define LOADERS_H_VERSION "$Id: loaders.h,v 1.26 2010/12/26 15:30:28 fabiankeil Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loaders.h,v $
@@ -49,7 +49,7 @@ struct configuration_spec;
 struct url_spec;
 
 extern unsigned int sweep(void);
-extern char *read_config_line(char *buf, size_t buflen, FILE *fp, unsigned long *linenum);
+extern char *read_config_line(FILE *fp, unsigned long *linenum, char **buf);
 extern int check_file_changed(const struct file_list * current,
                               const char * filename,
                               struct file_list ** newfl);