diff mbox series

Fix setting bootloader transaction marker

Message ID 20201120194208.113859-1-christian.storm@siemens.com
State Accepted
Headers show
Series Fix setting bootloader transaction marker | expand

Commit Message

Christian Storm Nov. 20, 2020, 7:42 p.m. UTC
do_save_state()'s value range check is for update_state_t values
and most probably fails on string values like "in_progress" as
used by the bootloader transaction marker.

While at it, cover all update_state_t values in get_state_string().

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 core/state.c    | 8 +++++++-
 include/state.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/core/state.c b/core/state.c
index e1ce5fe..8ddd760 100644
--- a/core/state.c
+++ b/core/state.c
@@ -60,7 +60,13 @@  server_op_res_t save_state(char *key, update_state_t value)
 
 server_op_res_t save_state_string(char *key, update_state_t value)
 {
-	return do_save_state(key, get_state_string(value));
+	CHECK_STATE_VAR(key);
+	if (!value)
+		return -EINVAL;
+	if (value < STATE_OK || value > STATE_LAST)
+		return -EINVAL;
+	return bootloader_env_set(key, get_state_string(value)) == 0 ?
+		SERVER_OK : SERVER_EERR;
 }
 
 server_op_res_t read_state(char *key, update_state_t *value)
diff --git a/include/state.h b/include/state.h
index e6c6cfa..f006b6c 100644
--- a/include/state.h
+++ b/include/state.h
@@ -52,9 +52,15 @@  static inline char* get_state_string(update_state_t state) {
 	switch (state) {
 		case STATE_IN_PROGRESS: return (char*)"in_progress";
 		case STATE_FAILED: return (char*)"failed";
+		case STATE_OK: return (char*)"ok";
+		case STATE_INSTALLED: return (char*)"installed";
+		case STATE_TESTING: return (char*)"testing";
+		case STATE_NOT_AVAILABLE: return (char*)"not_available";
+		case STATE_ERROR: return (char*)"error";
+		case STATE_WAIT: return (char*)"wait";
 		default: break;
 	}
-	return (char*)state;
+	return (char*)"<nil>";
 }
 
 server_op_res_t save_state(char *key, update_state_t value);