Skip to content

Commit cfb19f0

Browse files
committed
add capacity==0 check in ringbuffer init
1 parent cfd9594 commit cfb19f0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/wh_log_ringbuf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ int whLogRingbuf_Init(void* c, const void* cf)
4444

4545
/* Calculate capacity (number of complete entries that fit in buffer) */
4646
capacity = config->buffer_size / sizeof(whLogEntry);
47+
/* Capacity must be able to hold at least one log entry, specifically to
48+
* prevent divide-by-zeros in the rollover logic */
49+
if (capacity == 0) {
50+
return WH_ERROR_BADARGS;
51+
}
4752

4853
/* Initialize context */
4954
memset(context, 0, sizeof(*context));

0 commit comments

Comments
 (0)