Skip to content

Commit

Permalink
[FIXED] Fix heap buffer overflow in _fetch (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler92 authored and levb committed Oct 1, 2024
1 parent 6a74cf6 commit 2d9fbfd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/js.c
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ _fetch(natsMsgList *list, natsSubscription *sub, jsFetchRequest *req, bool simpl
natsStatus s = NATS_OK;
natsMsg **msgs = NULL;
int count = 0;
int batch = 0;
natsConnection *nc = NULL;
const char *subj = NULL;
const char *rply = NULL;
Expand Down Expand Up @@ -1916,9 +1917,10 @@ _fetch(natsMsgList *list, natsSubscription *sub, jsFetchRequest *req, bool simpl
noWait = req->NoWait;
}

batch = req->Batch;
// If we have OK and not all messages, we will send a fetch
// request to the server.
while ((s == NATS_OK) && (count != req->Batch) && ((req->MaxBytes == 0) || (size < req->MaxBytes)))
while ((s == NATS_OK) && (count != batch) && ((req->MaxBytes == 0) || (size < req->MaxBytes)))
{
natsMsg *msg = NULL;
bool usrMsg = false;
Expand All @@ -1933,7 +1935,7 @@ _fetch(natsMsgList *list, natsSubscription *sub, jsFetchRequest *req, bool simpl
if ((s == NATS_OK) && sendReq)
{
sendReq = false;
req->Batch = req->Batch - (int64_t) count;
req->Batch = req->Batch - count;
req->Expires = NATS_MILLIS_TO_NANOS(timeout);
req->NoWait = noWait;
s = _sendPullRequest(nc, subj, rply, &buf, req);
Expand Down

0 comments on commit 2d9fbfd

Please sign in to comment.