@@ -54,6 +54,7 @@ void *get_node_libconfig(config_t *cfg, const char **nodes);
#define get_field_cfg(e, path, dest)
#define find_root_libconfig(cfg, nodes, depth) (NULL)
#define get_node_libconfig(cfg, nodes) (NULL)
+#define is_field_numeric_cfg(e, path) (false)
#endif
#ifdef CONFIG_JSON
@@ -85,6 +86,7 @@ void *get_node_json(json_object *root, const char **nodes);
#define json_object_array_length(a) (0)
#define find_root_json(root, nodes, depth) (NULL)
#define get_node_json(root, nodes) (NULL)
+#define is_field_numeric_json(e, path) (false)
#endif
bool is_field_numeric(parsertype p, void *e, const char *path);
@@ -398,8 +398,6 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im
GET_FIELD_STRING(p, elem, "mtdname", image->mtdname);
GET_FIELD_STRING(p, elem, "filesystem", image->filesystem);
GET_FIELD_STRING(p, elem, "type", image->type);
- get_field(p, elem, "offset", &offset);
- GET_FIELD_STRING(p, elem, "offset", seek_str);
GET_FIELD_STRING(p, elem, "data", image->type_data);
get_hash_value(p, elem, image->sha256);
@@ -407,9 +405,11 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im
* offset can be set as number or string. As string,
* multiplier suffixes are allowed
*/
- if (offset)
+ if (is_field_numeric(p, elem, "offset")) {
+ get_field(p, elem, "offset", &offset);
image->seek = offset;
- else {
+ } else {
+ GET_FIELD_STRING(p, elem, "offset", seek_str);
/* convert the offset handling multiplicative suffixes */
image->seek = ustrtoull(seek_str, NULL, 0);
if (errno){
get_field(p, elem, "offset", &offset) in case of JSON does not return 0 if field is a string, causing a wrong offset to be evaluated. This bug does not happen if libconfig is the parser. Call is_field_numeric() in advance to check if offset is set as number or string. Signed-off-by: Stefano Babic <stefano.babic@swupdate.org> Reported-by: Einar Jón <tolvupostur@gmail.com> --- include/parselib.h | 2 ++ parser/parser.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-)