From: kostas <> Date: Sat, 3 Jan 1998 05:39:14 +0000 (+0000) Subject: code cleanup+security (sprintf->snprintf) X-Git-Tag: SQUID_3_0_PRE1~4273 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25347664efc8fcf96e6410cd5312f30d859ea872;p=thirdparty%2Fsquid.git code cleanup+security (sprintf->snprintf) --- diff --git a/lib/GNUregex.c b/lib/GNUregex.c index 00d55c0839..54b846c2aa 100644 --- a/lib/GNUregex.c +++ b/lib/GNUregex.c @@ -49,15 +49,6 @@ * `BSTRING', as far as I know, and neither of them use this code. */ #if HAVE_STRING_H || STDC_HEADERS #include -#ifndef bcmp -#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) -#endif -#ifndef bcopy -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif -#ifndef bzero -#define bzero(s, n) memset ((s), 0, (n)) -#endif #else #include #endif @@ -98,7 +89,7 @@ init_syntax_once() if (done) return; - bzero(re_syntax_table, sizeof re_syntax_table); + memset(re_syntax_table, 0, sizeof re_syntax_table); for (c = 'a'; c <= 'z'; c++) re_syntax_table[c] = Sword; @@ -208,7 +199,7 @@ char *alloca(); /* Assumes a `char *destination' variable. */ #define REGEX_REALLOCATE(source, osize, nsize) \ (destination = (char *) alloca (nsize), \ - bcopy (source, destination, osize), \ + xmemcpy (destination, source, osize), \ destination) #endif /* not REGEX_MALLOC */ @@ -1333,7 +1324,7 @@ regex_compile(pattern, size, syntax, bufp) BUF_PUSH((1 << BYTEWIDTH) / BYTEWIDTH); /* Clear the whole map. */ - bzero(b, (1 << BYTEWIDTH) / BYTEWIDTH); + memset(b, 0, (1 << BYTEWIDTH) / BYTEWIDTH); /* charset_not matches newline according to a syntax bit. */ if ((re_opcode_t) b[-2] == charset_not @@ -2492,7 +2483,7 @@ re_compile_fastmap(bufp) assert(fastmap != NULL && p != NULL); INIT_FAIL_STACK(); - bzero(fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ + memset(fastmap, 0, 1 << BYTEWIDTH); /* Assume nothing's valid. */ bufp->fastmap_accurate = 1; /* It will be when we're done. */ bufp->can_be_null = 0; @@ -3694,7 +3685,7 @@ re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) * past them. */ if (translate ? bcmp_translate(d, d2, mcnt, translate) - : bcmp(d, d2, mcnt)) + : memcmp(d, d2, mcnt)) goto fail; d += mcnt, d2 += mcnt; } diff --git a/lib/rfc1123.c b/lib/rfc1123.c index 87cf4c6e39..f2e189ad67 100644 --- a/lib/rfc1123.c +++ b/lib/rfc1123.c @@ -1,6 +1,6 @@ /* - * $Id: rfc1123.c,v 1.10 1997/12/30 02:50:36 wessels Exp $ + * $Id: rfc1123.c,v 1.11 1998/01/02 22:39:15 kostas Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -306,7 +306,7 @@ mkhttpdlogtime(const time_t * t) day_offset = 1; len = strftime(buf, 127 - 5, "%d/%b/%Y:%H:%M:%S ", lt); - sprintf(buf + len, "%+03d%02d", + snprintf(buf + len, 128-len, "%+03d%02d", (min_offset / 60) % 24, min_offset % 60); #else /* USE_GMT */ diff --git a/lib/safe_inet_addr.c b/lib/safe_inet_addr.c index 156c0f72f4..595b530d4d 100644 --- a/lib/safe_inet_addr.c +++ b/lib/safe_inet_addr.c @@ -38,7 +38,7 @@ safe_inet_addr(const char *buf, struct in_addr *addr) return 0; if (a4 < 0 || a4 > 255) return 0; - sprintf(addrbuf, "%d.%d.%d.%d", a1, a2, a3, a4); + snprintf(addrbuf,32, "%d.%d.%d.%d", a1, a2, a3, a4); A.s_addr = inet_addr(addrbuf); if (addr) addr->s_addr = A.s_addr; diff --git a/lib/util.c b/lib/util.c index 194990cf85..d5dc60dca7 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,6 +1,6 @@ /* - * $Id: util.c,v 1.36 1997/12/02 00:17:27 wessels Exp $ + * $Id: util.c,v 1.37 1998/01/02 22:39:17 kostas Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -208,7 +208,7 @@ check_free(void *s) break; } if (I == DBG_ARRY_SZ) { - sprintf(msg, "xfree: ERROR: s=%p not found!", s); + snprintf(msg, 128, "xfree: ERROR: s=%p not found!", s); (*failure_notify) (msg); } } @@ -224,7 +224,7 @@ check_malloc(void *p, size_t sz) continue; Q = P + malloc_size[B][I]; if (P <= p && p < Q) { - sprintf(msg, "xmalloc: ERROR: p=%p falls in P=%p+%d", + snprintf(msg, 128, "xmalloc: ERROR: p=%p falls in P=%p+%d", p, P, malloc_size[B][I]); (*failure_notify) (msg); } @@ -285,7 +285,7 @@ xmalloc(size_t sz) sz = 1; if ((p = malloc(sz)) == NULL) { if (failure_notify) { - sprintf(msg, "xmalloc: Unable to allocate %d bytes!\n", + snprintf(msg, 128, "xmalloc: Unable to allocate %d bytes!\n", (int) sz); (*failure_notify) (msg); } else { @@ -351,7 +351,7 @@ xrealloc(void *s, size_t sz) sz = 1; if ((p = realloc(s, sz)) == NULL) { if (failure_notify) { - sprintf(msg, "xrealloc: Unable to reallocate %d bytes!\n", + snprintf(msg, 128, "xrealloc: Unable to reallocate %d bytes!\n", (int) sz); (*failure_notify) (msg); } else { @@ -386,7 +386,7 @@ xcalloc(int n, size_t sz) sz = 1; if ((p = calloc(n, sz)) == NULL) { if (failure_notify) { - sprintf(msg, "xcalloc: Unable to allocate %d blocks of %d bytes!\n", + snprintf(msg, 128, "xcalloc: Unable to allocate %d blocks of %d bytes!\n", (int) n, (int) sz); (*failure_notify) (msg); } else { @@ -440,7 +440,7 @@ xstrerror(void) static char xstrerror_buf[BUFSIZ]; if (errno < 0 || errno >= sys_nerr) return ("Unknown"); - sprintf(xstrerror_buf, "(%d) %s", errno, strerror(errno)); + snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", errno, strerror(errno)); return xstrerror_buf; } @@ -454,7 +454,7 @@ xbstrerror(int err) static char xbstrerror_buf[BUFSIZ]; if (err < 0 || err >= sys_nerr) return ("Unknown"); - sprintf(xbstrerror_buf, "(%d) %s", err, strerror(err)); + snprintf(xbstrerror_buf, BUFSIZ, "(%d) %s", err, strerror(err)); return xbstrerror_buf; } #endif