Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "maybe fix, at least doesn't crash" #184

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/kws.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,12 +1432,14 @@ KS_DECLARE(ks_ssize_t) kws_read_frame(kws_t *kws, kws_opcode_t *oc, uint8_t **da
blen = (int)(kws->body - kws->bbuffer);

/* The bbuffer for the body of the message should always be 1 larger than the total size (for null term) */
/* Check if existing buffer size is big enough already */
if (need + blen > (ks_ssize_t)kws->bbuflen) {
if (blen + kws->plen >= (ks_ssize_t)kws->bbuflen) {
void *tmp;

/* Increase allocated buffer size by difference needed including extra NULL byte */
kws->bbuflen += need + 1;
/* must be a sum of the size already written to the body (blen) plus the size to be written (kws->plen) */
kws->bbuflen = blen + kws->plen; /* total size */

/* and 1 more for NULL term */
kws->bbuflen++;

if (kws->payload_size_max && kws->bbuflen > kws->payload_size_max) {
/* size limit */
Expand Down