Skip to content

Commit dfea3b9

Browse files
committed
rimage: select proper parse toml key functions based on data size
Select proper parse TOML keys functions to avoid int overflow errors Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
1 parent d015d57 commit dfea3b9

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

tools/rimage/src/adsp_config.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ static int parse_cse(const toml_table_t *toml, struct parse_ctx *pctx,
270270
hdr->header_length = sizeof(struct CsePartitionDirHeader);
271271

272272
/* configurable fields */
273-
hdr->header_version = parse_uint32_key(cse, &ctx, "header_version", 1, &ret);
273+
hdr->header_version = parse_uint8_key(cse, &ctx, "header_version", 1, &ret);
274274
if (ret < 0)
275275
return ret;
276276

277-
hdr->entry_version = parse_uint32_key(cse, &ctx, "entry_version", 1, &ret);
277+
hdr->entry_version = parse_uint8_key(cse, &ctx, "entry_version", 1, &ret);
278278
if (ret < 0)
279279
return ret;
280280

@@ -382,11 +382,11 @@ static int parse_cse_v2_5(const toml_table_t *toml, struct parse_ctx *pctx,
382382
hdr->header_length = sizeof(struct CsePartitionDirHeader_v2_5);
383383

384384
/* configurable fields */
385-
hdr->header_version = parse_uint32_key(cse, &ctx, "header_version", 2, &ret);
385+
hdr->header_version = parse_uint8_key(cse, &ctx, "header_version", 2, &ret);
386386
if (ret < 0)
387387
return ret;
388388

389-
hdr->entry_version = parse_uint32_key(cse, &ctx, "entry_version", 1, &ret);
389+
hdr->entry_version = parse_uint8_key(cse, &ctx, "entry_version", 1, &ret);
390390
if (ret < 0)
391391
return ret;
392392

@@ -771,11 +771,11 @@ static int parse_signed_pkg(const toml_table_t *toml, struct parse_ctx *pctx,
771771
if (ret < 0)
772772
return ret;
773773

774-
out->fw_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_type", 0, &ret);
774+
out->fw_type = parse_uint8_hex_key(signed_pkg, &ctx, "fw_type", 0, &ret);
775775
if (ret < 0)
776776
return ret;
777777

778-
out->fw_sub_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_sub_type", 0, &ret);
778+
out->fw_sub_type = parse_uint8_hex_key(signed_pkg, &ctx, "fw_sub_type", 0, &ret);
779779
if (ret < 0)
780780
return ret;
781781

@@ -835,15 +835,15 @@ static int parse_signed_pkg(const toml_table_t *toml, struct parse_ctx *pctx,
835835
if (ret < 0)
836836
return err_key_parse("module", NULL);
837837

838-
mod->type = parse_uint32_hex_key(module, &ctx, "type", 0x03, &ret);
838+
mod->type = parse_uint8_hex_key(module, &ctx, "type", 0x03, &ret);
839839
if (ret < 0)
840840
return err_key_parse("module", NULL);
841841

842-
mod->hash_algo = parse_uint32_hex_key(module, &ctx, "hash_algo", 0x02, &ret);
842+
mod->hash_algo = parse_uint8_hex_key(module, &ctx, "hash_algo", 0x02, &ret);
843843
if (ret < 0)
844844
return err_key_parse("module", NULL);
845845

846-
mod->hash_size = parse_uint32_hex_key(module, &ctx, "hash_size", 0x20, &ret);
846+
mod->hash_size = parse_uint16_hex_key(module, &ctx, "hash_size", 0x20, &ret);
847847
if (ret < 0)
848848
return err_key_parse("module", NULL);
849849

@@ -929,11 +929,11 @@ static int parse_signed_pkg_v2_5(const toml_table_t *toml, struct parse_ctx *pct
929929
if (ret < 0)
930930
return ret;
931931

932-
out->fw_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_type", 0, &ret);
932+
out->fw_type = parse_uint8_hex_key(signed_pkg, &ctx, "fw_type", 0, &ret);
933933
if (ret < 0)
934934
return ret;
935935

936-
out->fw_sub_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_sub_type", 0, &ret);
936+
out->fw_sub_type = parse_uint8_hex_key(signed_pkg, &ctx, "fw_sub_type", 0, &ret);
937937
if (ret < 0)
938938
return ret;
939939

@@ -993,15 +993,15 @@ static int parse_signed_pkg_v2_5(const toml_table_t *toml, struct parse_ctx *pct
993993
if (ret < 0)
994994
return err_key_parse("module", NULL);
995995

996-
mod->type = parse_uint32_hex_key(module, &ctx, "type", 0x03, &ret);
996+
mod->type = parse_uint8_hex_key(module, &ctx, "type", 0x03, &ret);
997997
if (ret < 0)
998998
return err_key_parse("module", NULL);
999999

1000-
mod->hash_algo = parse_uint32_hex_key(module, &ctx, "hash_algo", 0x00, &ret);
1000+
mod->hash_algo = parse_uint8_hex_key(module, &ctx, "hash_algo", 0x00, &ret);
10011001
if (ret < 0)
10021002
return err_key_parse("module", NULL);
10031003

1004-
mod->hash_size = parse_uint32_hex_key(module, &ctx, "hash_size", 0x30, &ret);
1004+
mod->hash_size = parse_uint16_hex_key(module, &ctx, "hash_size", 0x30, &ret);
10051005
if (ret < 0)
10061006
return err_key_parse("module", NULL);
10071007

@@ -1079,11 +1079,11 @@ static int parse_signed_pkg_ace_v1_5(const toml_table_t *toml, struct parse_ctx
10791079
if (ret < 0)
10801080
return ret;
10811081

1082-
out->fw_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_type", 0, &ret);
1082+
out->fw_type = parse_uint8_hex_key(signed_pkg, &ctx, "fw_type", 0, &ret);
10831083
if (ret < 0)
10841084
return ret;
10851085

1086-
out->fw_sub_type = parse_uint32_hex_key(signed_pkg, &ctx, "fw_sub_type", 0, &ret);
1086+
out->fw_sub_type = parse_uint8_hex_key(signed_pkg, &ctx, "fw_sub_type", 0, &ret);
10871087
if (ret < 0)
10881088
return ret;
10891089

@@ -1121,11 +1121,11 @@ static int parse_signed_pkg_ace_v1_5(const toml_table_t *toml, struct parse_ctx
11211121
if (ret < 0)
11221122
return err_key_parse("module", NULL);
11231123

1124-
mod->type = parse_uint32_hex_key(module, &ctx, "type", 0x03, &ret);
1124+
mod->type = parse_uint8_hex_key(module, &ctx, "type", 0x03, &ret);
11251125
if (ret < 0)
11261126
return err_key_parse("module", NULL);
11271127

1128-
mod->hash_algo = parse_uint32_hex_key(module, &ctx, "hash_algo", 0x00, &ret);
1128+
mod->hash_algo = parse_uint8_hex_key(module, &ctx, "hash_algo", 0x00, &ret);
11291129
if (ret < 0)
11301130
return err_key_parse("module", NULL);
11311131

@@ -1256,7 +1256,7 @@ static int parse_partition_info_ext(const toml_table_t *toml, struct parse_ctx *
12561256
if (ret < 0)
12571257
return err_key_parse("module", NULL);
12581258

1259-
mod->type = parse_uint32_hex_key(module, &ctx, "type", 0x03, &ret);
1259+
mod->type = parse_uint8_hex_key(module, &ctx, "type", 0x03, &ret);
12601260
if (ret < 0)
12611261
return err_key_parse("module", NULL);
12621262

@@ -1917,7 +1917,7 @@ static int parse_module(const toml_table_t *toml, struct parse_ctx *pctx,
19171917
if (ret < 0)
19181918
return err_key_parse("affinity_mask", NULL);
19191919

1920-
mod_man->instance_max_count = parse_uint32_hex_key(mod_entry, &ctx_entry,
1920+
mod_man->instance_max_count = parse_uint16_hex_key(mod_entry, &ctx_entry,
19211921
"instance_count", 1, &ret);
19221922
if (ret < 0)
19231923
return err_key_parse("instance_count", NULL);

0 commit comments

Comments
 (0)