net: lwm2m: shell: Add error check for string to float conversion

The result of string to float conversion in LwM2M shell write command
was not verified, which could result in incorrect data being written to
the resource.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2023-11-17 11:48:01 +01:00 committed by Carles Cufí
parent dd36592aa4
commit ec50e5393c

View file

@ -328,8 +328,10 @@ static int cmd_write(const struct shell *sh, size_t argc, char **argv)
} else if (strcmp(dtype, "-f") == 0) {
double new = 0;
lwm2m_atof(value, &new); /* Convert string -> float */
ret = lwm2m_set_f64(&path, new);
ret = lwm2m_atof(value, &new); /* Convert string -> float */
if (ret == 0) {
ret = lwm2m_set_f64(&path, new);
}
} else { /* All the types using stdlib funcs*/
char *e;