Skip to content

Commit dc2cdaa

Browse files
authored
Smart Charging module fixes (#260)
1 parent 12d4868 commit dc2cdaa

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Allow `nullptr` as parameter for `mocpp_set_console_out` ([#224](https://github.com/matth-x/MicroOcpp/issues/224))
88
- Fix `mocpp_tick_ms()` on esp-idf roll-over after 12 hours
99
- Pin ArduinoJson to v6.21 ([#245](https://github.com/matth-x/MicroOcpp/issues/245))
10+
- Fix bounds checking in SmartCharging module ([#260](https://github.com/matth-x/MicroOcpp/pull/260))
1011

1112
## [1.0.0] - 2023-10-22
1213

src/MicroOcpp/Model/SmartCharging/SmartChargingModel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ bool MicroOcpp::loadChargingSchedule(JsonObject& json, ChargingSchedule& out) {
480480
return false;
481481
}
482482

483+
if (periodJsonArray.size() > CHARGINGSCHEDULEMAXPERIODS) {
484+
MO_DBG_WARN("exceed ChargingScheduleMaxPeriods");
485+
return false;
486+
}
487+
483488
for (JsonObject periodJson : periodJsonArray) {
484489
out.chargingSchedulePeriod.push_back(ChargingSchedulePeriod());
485490
if (!loadChargingSchedulePeriod(periodJson, out.chargingSchedulePeriod.back())) {

src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ std::unique_ptr<ChargingSchedule> SmartChargingConnector::getCompositeSchedule(i
274274
size_t SmartChargingConnector::getChargingProfilesCount() {
275275
size_t chargingProfilesCount = 0;
276276
for (size_t i = 0; i < CHARGEPROFILEMAXSTACKLEVEL + 1; i++) {
277-
if (ChargePointTxDefaultProfile[i]) {
277+
if (TxDefaultProfile[i]) {
278278
chargingProfilesCount++;
279279
}
280-
if (ChargePointMaxProfile[i]) {
280+
if (TxProfile[i]) {
281281
chargingProfilesCount++;
282282
}
283283
}

src/MicroOcpp/Operations/SetChargingProfile.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,21 @@ void SetChargingProfile::processReq(JsonObject payload) {
5757
errorCode = "PropertyConstraintViolation";
5858
return;
5959
}
60-
if (!connector->getTransaction() || !connector->getTransaction()->isRunning()) {
60+
61+
auto& transaction = connector->getTransaction();
62+
if (!transaction || !connector->getTransaction()->isRunning()) {
6163
//no transaction running, reject profile
6264
accepted = false;
6365
return;
6466
}
6567

68+
if (chargingProfile->getTransactionId() < 0 ||
69+
chargingProfile->getTransactionId() != transaction->getTransactionId()) {
70+
//transactionId undefined / mismatch
71+
accepted = false;
72+
return;
73+
}
74+
6675
//seems good
6776
} else if (chargingProfile->getChargingProfilePurpose() == ChargingProfilePurposeType::ChargePointMaxProfile) {
6877
if (connectorId > 0) {

0 commit comments

Comments
 (0)