Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[PATCH v2 0/10] parser: fix various data type problems

9 views
Skip to first unread message

Christian Eggers

unread,
Jul 12, 2024, 11:23:13 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
There are places where the pointer supplied to GET_FIELD_foo()
doesn't match the pointer cast used for assigned the value within
the libconfig/libjson adapters (e.g 'bool *' vs. 'unsigned int *').
Additionally weaken the "type equality" requirements, so that
older SWU files can be used furthermore.

v2:
- add patches 1/10..9/10
- weaken "type equality" requirements between INT and INT64

Christian Eggers (10):
parser: field_type_t::TYPE_STRING: remove
parser: field_type_t::TYPE_FLOAT: rename to TYPE_DOUBLE
Fix usage of GET_FIELD_BOOL()
Fix usage of GET_FIELD_INT()
Fix usage of GET_FIELD_INT64()
parser: GET_FIELD_*: add type safety
parser: use SWUpdate internal type as master
parser: add forward declaration for struct swupdate_cfg
parser: print warning in case of type mismatch in sw-description
parser: libconfig: allow implicit conversion from INT to INT64

core/stream_interface.c | 2 +-
corelib/parsing_library_libconfig.c | 40 +++++++++++++++++------------
corelib/parsing_library_libjson.c | 38 +++++++++++++--------------
corelib/server_utils.c | 2 +-
corelib/swupdate_settings.c | 4 +--
include/parselib.h | 31 +++++++++++++++++-----
include/parsers.h | 2 ++
include/swupdate_image.h | 6 ++---
mongoose/mongoose_interface.c | 2 +-
parser/parser.c | 2 +-
10 files changed, 79 insertions(+), 50 deletions(-)

--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:23:26 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
This isn't used anywhere (GET_FIELD_STRING() uses a separate method for
retrieving strings). Get rid of dangerous strcpy() call in json parser.

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
corelib/parsing_library_libconfig.c | 5 -----
corelib/parsing_library_libjson.c | 5 -----
include/parselib.h | 1 -
3 files changed, 11 deletions(-)

diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
index ddb79f6fb152..a3535e9ec0e4 100644
--- a/corelib/parsing_library_libconfig.c
+++ b/corelib/parsing_library_libconfig.c
@@ -27,8 +27,6 @@ static unsigned int map_field_type(field_type_t type)
return CONFIG_TYPE_INT;
case TYPE_INT64:
return CONFIG_TYPE_INT64;
- case TYPE_STRING:
- return CONFIG_TYPE_STRING;
case TYPE_BOOL:
return CONFIG_TYPE_BOOL;
case TYPE_FLOAT:
@@ -51,9 +49,6 @@ static void get_value_libconfig(const config_setting_t *e, void *dest, field_typ
case CONFIG_TYPE_INT64:
*(long long *)dest = config_setting_get_int64(e);
break;
- case CONFIG_TYPE_STRING:
- dest = (void *)config_setting_get_string(e);
- break;
case CONFIG_TYPE_BOOL:
*(bool *)dest = config_setting_get_bool(e);
break;
diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index 4728d200fc8e..86646676d419 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -28,8 +28,6 @@ static json_type map_field_type(field_type_t type)
case TYPE_INT:
case TYPE_INT64:
return json_type_int;
- case TYPE_STRING:
- return json_type_string;
case TYPE_BOOL:
return json_type_boolean;
case TYPE_FLOAT:
@@ -133,9 +131,6 @@ static void get_value_json(json_object *e, void *dest, field_type_t expected_typ
case json_type_int:
*(unsigned int *)dest = json_object_get_int(e);
break;
- case json_type_string:
- strcpy(dest, json_object_get_string(e));
- break;
case json_type_double:
*(double *)dest = json_object_get_double(e);
break;
diff --git a/include/parselib.h b/include/parselib.h
index 99b6519fa480..b0142ff26840 100644
--- a/include/parselib.h
+++ b/include/parselib.h
@@ -27,7 +27,6 @@ typedef enum {
typedef enum {
TYPE_INT,
TYPE_INT64,
- TYPE_STRING,
TYPE_BOOL,
TYPE_FLOAT
} field_type_t;
--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:23:32 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
The libconfig/libjson adapters use "casts to double pointer" in this
case, so lets name it DOUBLE rather than FLOAT.

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
corelib/parsing_library_libconfig.c | 2 +-
corelib/parsing_library_libjson.c | 2 +-
include/parselib.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
index a3535e9ec0e4..ea4b03a476f5 100644
--- a/corelib/parsing_library_libconfig.c
+++ b/corelib/parsing_library_libconfig.c
@@ -29,7 +29,7 @@ static unsigned int map_field_type(field_type_t type)
return CONFIG_TYPE_INT64;
case TYPE_BOOL:
return CONFIG_TYPE_BOOL;
- case TYPE_FLOAT:
+ case TYPE_DOUBLE:
return CONFIG_TYPE_FLOAT;
default: /* not supported in SWUpdate */
return CONFIG_TYPE_NONE;
diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index 86646676d419..187e4eadcc16 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -30,7 +30,7 @@ static json_type map_field_type(field_type_t type)
return json_type_int;
case TYPE_BOOL:
return json_type_boolean;
- case TYPE_FLOAT:
+ case TYPE_DOUBLE:
return json_type_double;
default: /* not supported in SWUpdate */
return json_type_null;
diff --git a/include/parselib.h b/include/parselib.h
index b0142ff26840..4a8717e0aad2 100644
--- a/include/parselib.h
+++ b/include/parselib.h
@@ -28,7 +28,7 @@ typedef enum {
TYPE_INT,
TYPE_INT64,
TYPE_BOOL,
- TYPE_FLOAT
+ TYPE_DOUBLE
} field_type_t;

typedef void (*iterate_callback)(const char *name, const char *value,
--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:24:01 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
Add explicit pointer casts and sync behavior between libjson and
libconfig adaptors.

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
corelib/parsing_library_libjson.c | 2 +-
corelib/server_utils.c | 2 +-
corelib/swupdate_settings.c | 4 ++--
mongoose/mongoose_interface.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index d454aa79c540..fee7bbe3ad7b 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -129,7 +129,7 @@ static void get_value_json(json_object *e, void *dest, field_type_t expected_typ
*(bool *)dest = json_object_get_boolean(e);
break;
case json_type_int:
- *(unsigned int *)dest = json_object_get_int(e);
+ *(int *)dest = json_object_get_int(e);
break;
case json_type_double:
*(double *)dest = json_object_get_double(e);
diff --git a/corelib/server_utils.c b/corelib/server_utils.c
index 33c2d9a07ae2..e38425638a34 100644
--- a/corelib/server_utils.c
+++ b/corelib/server_utils.c
@@ -22,7 +22,7 @@ int channel_settings(void *elem, void *data)
channel_data_t *chan = (channel_data_t *)data;

GET_FIELD_INT(LIBCFG_PARSER, elem, "retry",
- &chan->retries);
+ (int *)&chan->retries);

GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "max-download-speed", tmp);
if (strlen(tmp)) {
diff --git a/corelib/swupdate_settings.c b/corelib/swupdate_settings.c
index 28d89a1436c7..e23c9f296606 100644
--- a/corelib/swupdate_settings.c
+++ b/corelib/swupdate_settings.c
@@ -95,8 +95,8 @@ static int get_run_as(void *elem, void *data)
{
struct run_as *pid = (struct run_as *)data;

- GET_FIELD_INT(LIBCFG_PARSER, elem, "userid", &pid->userid);
- GET_FIELD_INT(LIBCFG_PARSER, elem, "groupid", &pid->groupid);
+ GET_FIELD_INT(LIBCFG_PARSER, elem, "userid", (int *)&pid->userid);
+ GET_FIELD_INT(LIBCFG_PARSER, elem, "groupid", (int *)&pid->groupid);

return 0;
}
diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 3fbe88e2ca54..8635bbaf4c82 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -770,7 +770,7 @@ static int mongoose_settings(void *elem, void __attribute__ ((__unused__)) *dat
}
GET_FIELD_BOOL(LIBCFG_PARSER, elem, "run-postupdate", &run_postupdate);

- GET_FIELD_INT(LIBCFG_PARSER, elem, "timeout", &watchdog_conn);
+ GET_FIELD_INT(LIBCFG_PARSER, elem, "timeout", (int *)&watchdog_conn);

return 0;
}
--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:24:02 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
GET_FIELD_BOOL(), expects a pointer to a bool value. Synchronize
behavior between libconfig and libjson adaptors.

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
core/stream_interface.c | 2 +-
corelib/parsing_library_libjson.c | 2 +-
include/swupdate_image.h | 6 +++---
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/core/stream_interface.c b/core/stream_interface.c
index 5f3ad2e3fd93..eecc672ca157 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -288,7 +288,7 @@ static int extract_files(int fd, struct swupdate_cfg *software)
return -1;
}
/* Avoid trying to adjust again later */
- part->install_directly = 1;
+ part->install_directly = true;
}
}
img->fdin = fd;
diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index 187e4eadcc16..d454aa79c540 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -126,7 +126,7 @@ static void get_value_json(json_object *e, void *dest, field_type_t expected_typ
return;
switch (type) {
case json_type_boolean:
- *(unsigned int *)dest = json_object_get_boolean(e);
+ *(bool *)dest = json_object_get_boolean(e);
break;
case json_type_int:
*(unsigned int *)dest = json_object_get_int(e);
diff --git a/include/swupdate_image.h b/include/swupdate_image.h
index e214aafc2965..26ace79499ac 100644
--- a/include/swupdate_image.h
+++ b/include/swupdate_image.h
@@ -32,8 +32,8 @@ typedef enum {
struct sw_version {
char name[SWUPDATE_GENERAL_STRING_SIZE];
char version[SWUPDATE_GENERAL_STRING_SIZE];
- int install_if_different;
- int install_if_higher;
+ bool install_if_different;
+ bool install_if_higher;
LIST_ENTRY(sw_version) next;
};

@@ -57,7 +57,7 @@ struct img_type {
bool preserve_attributes; /* whether to preserve attributes in archives */
bool is_encrypted;
char ivt_ascii[33];
- int install_directly;
+ bool install_directly;
int is_script;
int is_partitioner;
struct dict properties;
--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:25:46 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
Add explicit pointer casts

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
parser/parser.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parser/parser.c b/parser/parser.c
index b092ebf6faad..c8571628c99a 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -427,7 +427,7 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im
* multiplier suffixes are allowed
*/
if (is_field_numeric(p, elem, "offset")) {
- GET_FIELD_INT64(p, elem, "offset", &offset);
+ GET_FIELD_INT64(p, elem, "offset", (long long *)&offset);
image->seek = offset;
} else {
GET_FIELD_STRING(p, elem, "offset", seek_str);
--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:26:13 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
Add separate inline functions in order to ensure that compatible
pointers are supplied.

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
include/parselib.h | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/include/parselib.h b/include/parselib.h
index 4a8717e0aad2..a49202a4b40f 100644
--- a/include/parselib.h
+++ b/include/parselib.h
@@ -65,6 +65,26 @@ void *find_root(parsertype p, void *root, const char **nodes);
void *get_node(parsertype p, void *root, const char **nodes);
bool set_find_path(const char **nodes, const char *newpath, char **tmp);

+static inline void get_field_bool(parsertype p, void *e, const char *path, bool *dest)
+{
+ get_field(p, e, path, dest, TYPE_BOOL);
+}
+
+static inline void get_field_int(parsertype p, void *e, const char *path, int *dest)
+{
+ get_field(p, e, path, dest, TYPE_INT);
+}
+
+static inline void get_field_int64(parsertype p, void *e, const char *path, long long *dest)
+{
+ get_field(p, e, path, dest, TYPE_INT64);
+}
+
+static inline void get_field_float(parsertype p, void *e, const char *path, double *dest)
+{
+ get_field(p, e, path, dest, TYPE_DOUBLE);
+}
+
#define GET_FIELD_STRING(p, e, name, d) \
get_field_string_with_size(p, e, name, d, sizeof(d))

@@ -74,13 +94,13 @@ bool set_find_path(const char **nodes, const char *newpath, char **tmp);
} while (0)

#define GET_FIELD_BOOL(p, e, path, dest) \
- get_field(p, e, path, dest, TYPE_BOOL)
+ get_field_bool(p, e, path, dest)

#define GET_FIELD_INT(p, e, path, dest) \
- get_field(p, e, path, dest, TYPE_INT)
+ get_field_int(p, e, path, dest)

#define GET_FIELD_INT64(p, e, path, dest) \
- get_field(p, e, path, dest, TYPE_INT64)
+ get_field_int64(p, e, path, dest)

#define GET_FIELD_FLOAT(p, e, path, dest) \
- get_field(p, e, path, dest, TYPE_FLOAT)
+ get_field_float(p, e, path, dest)
--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:26:22 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
The 'expected_type' decides which type the supplied pointer has (rather
than the type detected by the used config parser). So make this more
explicit. Additionally fix pointer mismatch for INT64 in json adapter.

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
corelib/parsing_library_libconfig.c | 14 +++++++-------
corelib/parsing_library_libjson.c | 20 +++++++++++---------
2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
index ea4b03a476f5..4442cefd3c07 100644
--- a/corelib/parsing_library_libconfig.c
+++ b/corelib/parsing_library_libconfig.c
@@ -39,20 +39,20 @@ static unsigned int map_field_type(field_type_t type)

static void get_value_libconfig(const config_setting_t *e, void *dest, field_type_t expected_type)
{
- int type = config_setting_type(e);
- if (type != map_field_type(expected_type))
+ int parsed_type = config_setting_type(e);
+ if (parsed_type != map_field_type(expected_type))
return;
- switch (type) {
- case CONFIG_TYPE_INT:
+ switch (expected_type) {
+ case TYPE_INT:
*(int *)dest = config_setting_get_int(e);
break;
- case CONFIG_TYPE_INT64:
+ case TYPE_INT64:
*(long long *)dest = config_setting_get_int64(e);
break;
- case CONFIG_TYPE_BOOL:
+ case TYPE_BOOL:
*(bool *)dest = config_setting_get_bool(e);
break;
- case CONFIG_TYPE_FLOAT:
+ case TYPE_DOUBLE:
*(double *)dest = config_setting_get_float(e);
break;
/* Do nothing, add if needed */
diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index fee7bbe3ad7b..74db22fc63f1 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -120,22 +120,24 @@ const char *get_field_string_json(json_object *e, const char *path)

static void get_value_json(json_object *e, void *dest, field_type_t expected_type)
{
- enum json_type type;
- type = json_object_get_type(e);
- if (type != map_field_type(expected_type))
+ enum json_type parsed_type;
+ parsed_type = json_object_get_type(e);
+ if (parsed_type != map_field_type(expected_type))
return;
- switch (type) {
- case json_type_boolean:
+ switch (expected_type) {
+ case TYPE_BOOL:
*(bool *)dest = json_object_get_boolean(e);
break;
- case json_type_int:
+ case TYPE_INT:
*(int *)dest = json_object_get_int(e);
break;
- case json_type_double:
- *(double *)dest = json_object_get_double(e);
+ case TYPE_INT64:
+ *(long long *)dest = json_object_get_int(e);
break;
- default:
+ case TYPE_DOUBLE:
+ *(double *)dest = json_object_get_double(e);
break;
+ /* Do nothing, add if needed */
}
}

--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:26:38 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
make parsers.h self-containing

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
include/parsers.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/include/parsers.h b/include/parsers.h
index 7d8abc1ff92c..a86c943b8890 100644
--- a/include/parsers.h
+++ b/include/parsers.h
@@ -15,6 +15,8 @@
#define SW_DESCRIPTION_FILENAME CONFIG_SWDESCRIPTION
#endif

+struct swupdate_cfg;
+
typedef int (*parser_fn)(struct swupdate_cfg *swcfg, const char *filename, char **error);

int parse(struct swupdate_cfg *swcfg, const char *filename);
--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:26:52 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
Print a warning if a value in sw-description doesn't match the expected
type. No assignment will happen in this case.

Signed-off-by: Christian Eggers <ceg...@arri.de>
---
corelib/parsing_library_libconfig.c | 9 ++++++---
corelib/parsing_library_libjson.c | 11 +++++++----
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
index 4442cefd3c07..e99fbe9dfe9a 100644
--- a/corelib/parsing_library_libconfig.c
+++ b/corelib/parsing_library_libconfig.c
@@ -17,6 +17,7 @@
#include "generated/autoconf.h"
#include "bsdqueue.h"
#include "util.h"
+#include "parsers.h"
#include "parselib.h"
#include "parselib-private.h"

@@ -37,11 +38,13 @@ static unsigned int map_field_type(field_type_t type)
}


-static void get_value_libconfig(const config_setting_t *e, void *dest, field_type_t expected_type)
+static void get_value_libconfig(const config_setting_t *e, const char *path, void *dest, field_type_t expected_type)
{
int parsed_type = config_setting_type(e);
- if (parsed_type != map_field_type(expected_type))
+ if (parsed_type != map_field_type(expected_type)) {
+ WARN("Type mismatch for %s field \"%s\"", SW_DESCRIPTION_FILENAME, path);
return;
+ }
switch (expected_type) {
case TYPE_INT:
*(int *)dest = config_setting_get_int(e);
@@ -120,7 +123,7 @@ void get_field_cfg(config_setting_t *e, const char *path, void *dest, field_type
if (!elem)
return;

- get_value_libconfig(elem, dest, type);
+ get_value_libconfig(elem, path, dest, type);
}

const char *get_field_string_libconfig(config_setting_t *e, const char *path)
diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index 74db22fc63f1..9635ac2a0c2d 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -17,6 +17,7 @@
#include "generated/autoconf.h"
#include "bsdqueue.h"
#include "util.h"
+#include "parsers.h"
#include "parselib.h"
#include "parselib-private.h"

@@ -118,12 +119,14 @@ const char *get_field_string_json(json_object *e, const char *path)
return NULL;
}

-static void get_value_json(json_object *e, void *dest, field_type_t expected_type)
+static void get_value_json(json_object *e, const char *path, void *dest, field_type_t expected_type)
{
enum json_type parsed_type;
parsed_type = json_object_get_type(e);
- if (parsed_type != map_field_type(expected_type))
+ if (parsed_type != map_field_type(expected_type)) {
+ WARN("Type mismatch for %s field \"%s\"", SW_DESCRIPTION_FILENAME, path);
return;
+ }
switch (expected_type) {
case TYPE_BOOL:
*(bool *)dest = json_object_get_boolean(e);
@@ -164,9 +167,9 @@ void get_field_json(json_object *e, const char *path, void *dest, field_type_t t

if (path) {
if (json_object_object_get_ex(e, path, &fld))
- get_value_json(fld, dest, type);
+ get_value_json(fld, path, dest, type);
} else {
- get_value_json(e, dest, type);
+ get_value_json(e, path, dest, type);
}
}

--
2.44.1

Christian Eggers

unread,
Jul 12, 2024, 11:27:19 AM7/12/24
to swup...@googlegroups.com, Christian Eggers
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 <ceg...@arri.de>
---
corelib/parsing_library_libconfig.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

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:
--
2.44.1

Stefano Babic

unread,
Jul 13, 2024, 4:55:51 AM7/13/24
to Christian Eggers, swup...@googlegroups.com
On 12.07.24 17:22, Christian Eggers wrote:
> This isn't used anywhere (GET_FIELD_STRING() uses a separate method for
> retrieving strings).

Yes, that's true - this is at the moment dead code, implemented just for
completeness.

> Get rid of dangerous strcpy() call in json parser.
>

We can drop it.
Acked-by: Stefano Babic <stefan...@swupdate.org>

Stefano Babic

unread,
Jul 13, 2024, 4:56:07 AM7/13/24
to Christian Eggers, swup...@googlegroups.com
On 12.07.24 17:22, Christian Eggers wrote:
Acked-by: Stefano Babic <stefan...@swupdate.org>

Stefano Babic

unread,
Jul 13, 2024, 4:58:30 AM7/13/24
to Christian Eggers, swup...@googlegroups.com
Acked-by: Stefano Babic <stefan...@swupdate.org>

Stefano Babic

unread,
Jul 13, 2024, 5:07:10 AM7/13/24
to Christian Eggers, swup...@googlegroups.com
Acked-by: Stefano Babic <stefan...@swupdate.org>

Stefano Babic

unread,
Jul 13, 2024, 6:30:02 AM7/13/24
to Christian Eggers, swup...@googlegroups.com
On 12.07.24 17:22, Christian Eggers wrote:
> There are places where the pointer supplied to GET_FIELD_foo()
> doesn't match the pointer cast used for assigned the value within
> the libconfig/libjson adapters (e.g 'bool *' vs. 'unsigned int *').
> Additionally weaken the "type equality" requirements, so that
> older SWU files can be used furthermore.

Series is fine for me, and it does what I meant. I am applying it.

Best regards,
Stefano
Reply all
Reply to author
Forward
0 new messages