Skip to content

Commit d0ae121

Browse files
authored
use H5_IS_BUFFER_OVERFLOW to check overflow
1 parent 826a425 commit d0ae121

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/H5Faccum.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,10 @@ H5F__accum_free(H5F_shared_t *f_sh, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr
881881
H5_CHECKED_ASSIGN(overlap_size, size_t, (addr + size) - accum->loc, haddr_t);
882882
new_accum_size = accum->size - overlap_size;
883883

884-
/* Ensure overlap_size and new_accum_size are within bounds */
885-
if (overlap_size > accum->alloc_size || new_accum_size > accum->alloc_size) {
886-
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
887-
"calculated sizes exceed allocated buffer size");
884+
/* Ensure that the memmove operation won't overflow past the buffer's allocated size */
885+
if (H5_IS_BUFFER_OVERFLOW(accum->buf + overlap_size, new_accum_size, accum->buf + accum->alloc_size)) {
886+
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
887+
"memmove operation would overflow buffer");
888888
}
889889

890890
/* Move the accumulator buffer information to eliminate the freed block */

0 commit comments

Comments
 (0)