Skip to content

Commit 432a757

Browse files
committed
Revert "maybe fix, at least doesn't crash"
1 parent f1af4fa commit 432a757

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/kws.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,12 +1432,14 @@ KS_DECLARE(ks_ssize_t) kws_read_frame(kws_t *kws, kws_opcode_t *oc, uint8_t **da
14321432
blen = (int)(kws->body - kws->bbuffer);
14331433

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

1439-
/* Increase allocated buffer size by difference needed including extra NULL byte */
1440-
kws->bbuflen += need + 1;
1438+
/* must be a sum of the size already written to the body (blen) plus the size to be written (kws->plen) */
1439+
kws->bbuflen = blen + kws->plen; /* total size */
1440+
1441+
/* and 1 more for NULL term */
1442+
kws->bbuflen++;
14411443

14421444
if (kws->payload_size_max && kws->bbuflen > kws->payload_size_max) {
14431445
/* size limit */

0 commit comments

Comments
 (0)