Skip to content

Commit

Permalink
[fix] UI: resolved a potential issue with index overflow in the daemo…
Browse files Browse the repository at this point in the history
…n communication protocol
  • Loading branch information
stenya committed Jan 22, 2024
1 parent 54889dc commit eff50e4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ui/src/daemon-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ function toJson(data) {
return res;
}

function getNextRequestNo() {
requestNo += 1;
if (requestNo > 0xffffffff) requestNo = 1;
return requestNo;
}

// send request to connected daemon
function send(request, reqNo) {
if (socket == null) throw Error("Unable to send request (socket is closed)");
Expand All @@ -211,10 +217,8 @@ function send(request, reqNo) {
);
}

if (typeof reqNo === "undefined") {
requestNo += 1;
reqNo = requestNo;
}
if (typeof reqNo === "undefined") reqNo = getNextRequestNo();

request.Idx = reqNo;

let serialized = toJson(request);
Expand Down Expand Up @@ -263,10 +267,10 @@ function addWaiter(waiter, timeoutMs) {
// which mach one of elements in 'waitRespCommandsList'.
// Otherwise, waiter will accept only response with correspond response index.
function sendRecv(request, waitRespCommandsList, timeoutMs) {
requestNo += 1;
let reqNo = getNextRequestNo();

const waiter = {
responseNo: requestNo,
responseNo: reqNo,
waitForCommandsList: waitRespCommandsList,
};

Expand All @@ -280,7 +284,7 @@ function sendRecv(request, waitRespCommandsList, timeoutMs) {

// send data
try {
send(request, requestNo);
send(request, reqNo);
} catch (e) {
console.error(e);
throw e;
Expand Down

0 comments on commit eff50e4

Please sign in to comment.