From aa54525e1b53596730fe64617ddc882ea12d3b5c Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Wed, 13 Mar 2024 16:17:26 +0200 Subject: [PATCH] Check ks buffer pointer overflow before dereferencing it. (#203) --- src/ks_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ks_buffer.c b/src/ks_buffer.c index 31d5857..03a0ed7 100644 --- a/src/ks_buffer.c +++ b/src/ks_buffer.c @@ -194,7 +194,7 @@ KS_DECLARE(ks_size_t) ks_buffer_packet_count(ks_buffer_t *buffer) e = (head + buffer->used); - for (p = head; p && *p && p < e; p++) { + for (p = head; p && p < e && *p; p++) { if (*p == '\n') { pe = p + 1; if (*pe == '\r') @@ -219,7 +219,7 @@ KS_DECLARE(ks_size_t) ks_buffer_read_packet(ks_buffer_t *buffer, void *data, ks_ e = (head + buffer->used); - for (p = head; p && *p && p < e; p++) { + for (p = head; p && p < e && *p; p++) { if (*p == '\n') { pe = p + 1; if (*pe == '\r')