]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
code cleanup+security (sprintf->snprintf)
authorkostas <>
Sat, 3 Jan 1998 05:39:14 +0000 (05:39 +0000)
committerkostas <>
Sat, 3 Jan 1998 05:39:14 +0000 (05:39 +0000)
lib/GNUregex.c
lib/rfc1123.c
lib/safe_inet_addr.c
lib/util.c

index 00d55c0839b6bece538287bc79d212ce5958357e..54b846c2aa012e767f0f1bde140a7f9df6afb273 100644 (file)
  * `BSTRING', as far as I know, and neither of them use this code.  */
 #if HAVE_STRING_H || STDC_HEADERS
 #include <string.h>
-#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 <strings.h>
 #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;
                }
index 87cf4c6e3914a0e38677ac4e96cec4edd1c0a246..f2e189ad676c03cfd218f5125d98847d23a6d852 100644 (file)
@@ -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 */
index 156c0f72f45558285e60abb16d39e81c3937f577..595b530d4d59b9d974004d16f4cc8c97768dc411 100644 (file)
@@ -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;
index 194990cf858e7230edb4c6f9d6c133c47d081f81..d5dc60dca71d39254c5bdd8220cc42a8a6240e42 100644 (file)
@@ -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