Skip to content

Commit 940d659

Browse files
authored
Merge pull request #171 from signalwire/realloc_crash
maybe fix, at least doesn't crash
2 parents a8f9394 + 1061879 commit 940d659

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/kws.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,14 +1432,12 @@ 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-
if (blen + kws->plen >= (ks_ssize_t)kws->bbuflen) {
1435+
/* Check if existing buffer size is big enough already */
1436+
if (need + blen > (ks_ssize_t)kws->bbuflen) {
14361437
void *tmp;
14371438

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++;
1439+
/* Increase allocated buffer size by difference needed including extra NULL byte */
1440+
kws->bbuflen += need + 1;
14431441

14441442
if (kws->payload_size_max && kws->bbuflen > kws->payload_size_max) {
14451443
/* size limit */

0 commit comments

Comments
 (0)