From: wessels <> Date: Fri, 24 Apr 1998 01:27:22 +0000 (+0000) Subject: Fixed buffer overruns from FTP server messages in errorConvert(). Now use X-Git-Tag: SQUID_3_0_PRE1~3452 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5da06f201925325db5c1c253d81bdf483b7ee684;p=thirdparty%2Fsquid.git Fixed buffer overruns from FTP server messages in errorConvert(). Now use wordlistCat() which checks lengths *before* calling snprintf() --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index ba8f733315..086399e5c3 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -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; } diff --git a/src/errorpage.cc b/src/errorpage.cc index ca98bbf90a..b51dbd1e81 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -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());