]> granicus.if.org Git - sudo/commitdiff
Oflow test of nmemb > SIZE_MAX / size is fine (don't need >=).
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 13 Mar 2003 17:00:31 +0000 (17:00 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 13 Mar 2003 17:00:31 +0000 (17:00 +0000)
Use memcpy() instead of strcpy() in estrdup() so this is strcpy()-free.

alloc.c

diff --git a/alloc.c b/alloc.c
index dbd973d38af5f54033b28b5ec4877904178239fb..0dd1ddab842d82b6c7649462b06477b690c68990 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -115,7 +115,7 @@ emalloc2(nmemb, size)
            Argv[0]);
        exit(1);
     }
-    if (nmemb >= SIZE_MAX / size) {
+    if (nmemb > SIZE_MAX / size) {
        (void) fprintf(stderr, "%s: internal error, emalloc2() overflow\n",
            Argv[0]);
        exit(1);
@@ -170,7 +170,7 @@ erealloc3(ptr, nmemb, size)
            Argv[0]);
        exit(1);
     }
-    if (nmemb >= SIZE_MAX / size) {
+    if (nmemb > SIZE_MAX / size) {
        (void) fprintf(stderr, "%s: internal error, erealloc3() overflow\n",
            Argv[0]);
        exit(1);
@@ -193,10 +193,12 @@ estrdup(src)
     const char *src;
 {
     char *dst = NULL;
+    size_t size;
 
     if (src != NULL) {
-       dst = (char *) emalloc(strlen(src) + 1);
-       (void) strcpy(dst, src);
+       size = strlen(src) + 1;
+       dst = (char *) emalloc(size);
+       (void) memcpy(dst, src, size);
     }
     return(dst);
 }