]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
zero all new memory from allocations
authorAndrew Tridgell <andrew@tridgell.net>
Wed, 22 Apr 2026 00:59:11 +0000 (10:59 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Wed, 22 Apr 2026 01:44:10 +0000 (11:44 +1000)
Change my_alloc() to use calloc instead of malloc so all fresh
allocations return zeroed memory. Also zero the expanded portion
in expand_item_list() after realloc, since it knows both old and
new sizes. This gives more predictable behaviour in case of bugs
where uninitialised or stale memory is accidentally accessed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
util1.c
util2.c

diff --git a/util1.c b/util1.c
index e65e05689824e32e05e9b70dee79053f2d7c8034..e477759a407e586742e5af44c0000ed1ac619c5b 100644 (file)
--- a/util1.c
+++ b/util1.c
@@ -1718,6 +1718,8 @@ void *expand_item_list(item_list *lp, size_t item_size, const char *desc, int in
                                new_ptr == lp->items ? " not" : "");
                }
 
+               memset((char *)new_ptr + lp->malloced * item_size, 0,
+                      (expand_size - lp->malloced) * item_size);
                lp->items = new_ptr;
                lp->malloced = expand_size;
        }
diff --git a/util2.c b/util2.c
index b59bff0a0b541b8f6837f6d87938ced8e5bac9b9..ce6f7de146d71924edfb3f06749c983f44a5b7cd 100644 (file)
--- a/util2.c
+++ b/util2.c
@@ -79,9 +79,7 @@ void *my_alloc(void *ptr, size_t num, size_t size, const char *file, int line)
                        who_am_i(), do_big_num(max_alloc, 0, NULL), src_file(file), line);
                exit_cleanup(RERR_MALLOC);
        }
-       if (!ptr)
-               ptr = malloc(num * size);
-       else if (ptr == do_calloc)
+       if (!ptr || ptr == do_calloc)
                ptr = calloc(num, size);
        else
                ptr = realloc(ptr, num * size);