fixed possible char array overflow (#20133)

* fixed possible char array overflow

the temporary char arrays size was fixed to 4 bytes before.
snprintf was set for the second char, so maximum size must be limited to 4-1, instead of 4 bytes.
to avoid further mistakes usage of a #define
(assuming that flaw made never problems as the number of attached sensors was usually <99)

* fixed possible char array overflow, optimization of preprocessor-constant name

instead using shortname TEMPLEN for the preprocessor-constant using a name specific to the thermostat-function to avoid interference with the rest of the project

* fixed possible char array overflow, no preprocessor constant neccessary

fixed possible char array overflow, without using preprocessor constant
This commit is contained in:
stegerfa 2023-12-01 09:14:42 +01:00 committed by GitHub
parent 9a010bdf7d
commit a9a734ddba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -1400,7 +1400,7 @@ void ThermostatGetLocalSensor(uint8_t ctr_output) {
&&(ctr_output < THERMOSTAT_SENSOR_NUMBER)) { &&(ctr_output < THERMOSTAT_SENSOR_NUMBER)) {
char temp[4]; char temp[4];
temp[0] = IndexSeparator(); temp[0] = IndexSeparator();
snprintf(&temp[1], 4, "%u", (ctr_output + 1)); snprintf(&temp[1], sizeof(temp)-1, "%u", (ctr_output + 1));
sensor_name.concat(temp); sensor_name.concat(temp);
} }
JsonParserToken value_token = root[sensor_name].getObject()[PSTR("Temperature")]; JsonParserToken value_token = root[sensor_name].getObject()[PSTR("Temperature")];