summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-09-27 13:06:22 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-09-27 13:06:22 +0000
commit28072499f8a27e624879072f4f835fb97861645e (patch)
tree15def6898967381021d43546a3000cfdacde0f8b /usr.bin
parent123c51ed4de560067a11b111a1f13c24140fd8c4 (diff)
rsync: fix reallocarray() usage in blkhash_set()
The well-named ERR() macro doesn't error out. Therefore an incorrect use of reallocarray() is actually a leak that is easily overlooked. Do it the right way by assigning to a temporary variable and preserve behavior by freeing and NULL-ing. ok claudio
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rsync/blocks.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/rsync/blocks.c b/usr.bin/rsync/blocks.c
index b300e41a04c..7b774e68df4 100644
--- a/usr.bin/rsync/blocks.c
+++ b/usr.bin/rsync/blocks.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: blocks.c,v 1.24 2024/09/18 10:22:36 job Exp $ */
+/* $OpenBSD: blocks.c,v 1.25 2024/09/27 13:06:21 tb Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -88,7 +88,8 @@ blkhash_alloc(void)
int
blkhash_set(struct blktab *p, const struct blkset *bset)
{
- size_t i, idx;
+ struct blkhash *blks;
+ size_t i, idx;
if (bset == NULL)
return 1;
@@ -100,11 +101,14 @@ blkhash_set(struct blktab *p, const struct blkset *bset)
/* Fill in the hashtable. */
- p->blks = reallocarray(p->blks, bset->blksz, sizeof(struct blkhash));
- if (p->blks == NULL) {
+ blks = reallocarray(p->blks, bset->blksz, sizeof(struct blkhash));
+ if (blks == NULL) {
ERR("reallocarray");
+ free(p->blks);
+ p->blks = NULL;
return 0;
}
+ p->blks = blks;
for (i = 0; i < bset->blksz; i++) {
p->blks[i].blk = &bset->blks[i];
idx = bset->blks[i].chksum_short % p->qsz;