]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed buffer overruns from FTP server messages in errorConvert(). Now use
authorwessels <>
Fri, 24 Apr 1998 01:27:22 +0000 (01:27 +0000)
committerwessels <>
Fri, 24 Apr 1998 01:27:22 +0000 (01:27 +0000)
wordlistCat() which checks lengths *before* calling snprintf()

src/cache_cf.cc
src/errorpage.cc

index ba8f73331548b6f23f9d2830f31007b5ca1c85e3..086399e5c3c590a3235414684df3d04ec6494751 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.278 1998/04/21 16:39:00 wessels Exp $
+ * $Id: cache_cf.cc,v 1.279 1998/04/23 19:27:23 wessels Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -117,6 +117,21 @@ wordlistAdd(wordlist ** list, const char *key)
     }
 }
 
+char *
+wordlistCat(const wordlist * w)
+{
+    LOCAL_ARRAY(char, buf, 16384);
+    int o = 0;
+    buf[0] = '\0';
+    while (NULL != w) {
+       if (o + strlen(w->key) > 16384)
+           break;
+       o += snprintf(buf + o, 16384 - o, "%s\n", w->key);
+       w = w->next;
+    }
+    return buf;
+}
+
 void
 intlistDestroy(intlist ** list)
 {
@@ -205,7 +220,7 @@ configDoConfigure(void)
     /* calculate Config.Swap.maxSize */
     Config.Swap.maxSize = 0;
     for (i = 0; i < Config.cacheSwap.n_configured; i++) {
-        SD = &Config.cacheSwap.swapDirs[i];;
+       SD = &Config.cacheSwap.swapDirs[i];;
        Config.Swap.maxSize += SD->max_size;
        n = 2 * SD->max_size / Config.Store.avgObjectSize;
        if (NULL == SD->map) {
@@ -214,7 +229,7 @@ configDoConfigure(void)
        } else if (n > SD->map->max_n_files) {
            /* it grew, need to expand */
            fm = file_map_create(n);
-            filemapCopy(SD->map, fm);
+           filemapCopy(SD->map, fm);
            filemapFreeMemory(SD->map);
            SD->map = fm;
        }
@@ -1292,7 +1307,7 @@ parse_wordlist(wordlist ** list)
 }
 
 static int
-check_null_wordlist(wordlist *w)
+check_null_wordlist(wordlist * w)
 {
     return w == NULL;
 }
index ca98bbf90a284468258ca548287a2408129390c8..b51dbd1e819d1cddbee36aa307de96333c80ee03 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: errorpage.cc,v 1.126 1998/04/22 02:07:32 wessels Exp $
+ * $Id: errorpage.cc,v 1.127 1998/04/23 19:27:22 wessels Exp $
  *
  * DEBUG: section 4     Error Generation
  * AUTHOR: Duane Wessels
@@ -373,8 +373,6 @@ errorConvert(char token, ErrorState * err)
     request_t *r = err->request;
     static char buf[CVT_BUF_SZ];
     const char *p = buf;
-    wordlist *w;
-    int o;
     switch (token) {
     case 'B':
        p = r ? ftpUrlWith2f(r) : "[no URL]";
@@ -404,13 +402,7 @@ errorConvert(char token, ErrorState * err)
        break;
     case 'g':
        /* FTP SERVER MESSAGE */
-       buf[0] = '\0';
-       o = 0;
-       for (w = err->ftp_server_msg; w; w = w->next) {
-           o += snprintf(buf + o, CVT_BUF_SZ - o, "%s\n", w->key);
-           if (o >= CVT_BUF_SZ)
-               break;
-       }
+       p = wordlistCat(err->ftp_server_msg);
        break;
     case 'h':
        snprintf(buf, CVT_BUF_SZ, "%s", getMyHostname());