From ec50e5393c98156729870167cb18645b13845d9f Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Fri, 17 Nov 2023 11:48:01 +0100 Subject: [PATCH] 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 --- subsys/net/lib/lwm2m/lwm2m_shell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_shell.c b/subsys/net/lib/lwm2m/lwm2m_shell.c index a4807d517f..a4cedf8cd6 100644 --- a/subsys/net/lib/lwm2m/lwm2m_shell.c +++ b/subsys/net/lib/lwm2m/lwm2m_shell.c @@ -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;