diff mbox series

[v2,10/10] parser: libconfig: allow implicit conversion from INT to INT64

Message ID 20240712152702.4751-1-ceggers@arri.de
State Accepted
Headers show
Series parser: fix various data type problems | expand

Commit Message

Christian Eggers July 12, 2024, 3:27 p.m. UTC
Since 1db0aefe57de ("Enforce type check in sw-description"),
GET_FIELD_INT64() does not assign a config value anymore if the type
detected by libconfig differs. This type check needs to be slightly
relaxed to allow assignment of parsed INT32 values when a INT64 is
expected. Otherwise this would require conversion of the sw-description
in the .swu files which breaks compatiblity with existing update files.

Link: https://groups.google.com/g/swupdate/c/UeALEHCAusQ
Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 corelib/parsing_library_libconfig.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
index e99fbe9dfe9a..8f227aa872e1 100644
--- a/corelib/parsing_library_libconfig.c
+++ b/corelib/parsing_library_libconfig.c
@@ -42,11 +42,21 @@  static void get_value_libconfig(const config_setting_t *e, const char *path, voi
 {
 	int parsed_type = config_setting_type(e);
 	if (parsed_type != map_field_type(expected_type)) {
-		WARN("Type mismatch for %s field \"%s\"", SW_DESCRIPTION_FILENAME, path);
-		return;
+		/* Weaken type equality requirements for INT/INT64 */
+		if ((parsed_type == CONFIG_TYPE_INT && expected_type == TYPE_INT64) ||
+		    (parsed_type == CONFIG_TYPE_INT64 && expected_type == TYPE_INT)) {
+			/* ignore type mismatch, handled well by libconfig */
+		} else {
+			WARN("Type mismatch for %s field \"%s\"", SW_DESCRIPTION_FILENAME, path);
+			return;
+		}
 	}
+
 	switch (expected_type) {
 	case TYPE_INT:
+		/* libconfig handles also 'L' suffixed integers as long as they fit
+		 * into INT32. Otherwise zero is returned
+		 */
 		*(int *)dest = config_setting_get_int(e);
 		break;
 	case TYPE_INT64: