Skip to content

Commit bb9591d

Browse files
committed
fix(ocpp/1.6): guard updateFirmwareSimulation against invalid delay bounds
Round-4 review (subagent #4 harmonization finding 3): six sites in updateFirmwareSimulation call randomInt(minDelay, maxDelay + 1) using function-parameter bounds. Current callers (constructor lines 586 and 596) pass no arguments so the safe defaults (maxDelay=30, minDelay=15) apply. But the parameters are exposed, and any future caller passing config-driven values could hit a randomInt RangeError inside the async firmware simulation loop that surfaces only as a generic caught error. Add an early isValidRandomIntBounds guard immediately after the existing checkChargingStationState guard. On invalid bounds, log an error naming the offending pair and return without scheduling any simulation. Defensive-only — no behavior change for the current default-only callers. Gates pass (format / typecheck / lint).
1 parent 5892299 commit bb9591d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import {
117117
isEmpty,
118118
isNotEmptyArray,
119119
isNotEmptyString,
120+
isValidRandomIntBounds,
120121
logger,
121122
sleep,
122123
truncateId,
@@ -1836,6 +1837,12 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
18361837
if (!checkChargingStationState(chargingStation, chargingStation.logPrefix())) {
18371838
return
18381839
}
1840+
if (!isValidRandomIntBounds(minDelay, maxDelay)) {
1841+
logger.error(
1842+
`${chargingStation.logPrefix()} ${moduleName}.updateFirmwareSimulation: invalid bounds minDelay=${minDelay.toString()}, maxDelay=${maxDelay.toString()} for randomInt(min, max + 1) — aborting firmware update simulation`
1843+
)
1844+
return
1845+
}
18391846
for (const { connectorId, connectorStatus } of chargingStation.iterateConnectors(true)) {
18401847
if (connectorStatus.transactionStarted === false) {
18411848
await sendAndSetConnectorStatus(chargingStation, {

0 commit comments

Comments
 (0)