Message ID | 20231215142251.52393-4-Michael.Glembotzki@iris-sensing.com |
---|---|
State | Changes Requested |
Headers | show |
Series | Add support for asymmetric decryption | expand |
Hi Michael, On 15.12.23 15:19, Michael Glembotzki wrote: > Only set the image ivt_ascii if the size is valid. > > Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com> > --- > core/parsing_library.c | 15 +++++++++++++++ > include/parselib.h | 1 + > parser/parser.c | 2 +- > 3 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/core/parsing_library.c b/core/parsing_library.c > index 8d21683..dcb3b73 100644 > --- a/core/parsing_library.c > +++ b/core/parsing_library.c > @@ -209,6 +209,21 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash) > ascii_to_hash(hash, hash_ascii); > } > > +void get_ivt_value(parsertype p, void *elem, char *ivt_ascii) > +{ > + size_t ivtlen; > + const char *s = NULL; > + s = get_field_string(p, elem, "ivt"); > + if (s) { > + ivtlen = strnlen(s, SWUPDATE_GENERAL_STRING_SIZE); > + if (ivtlen != (AES_BLK_SIZE*2)) { > + ERROR("Invalid ivt length"); > + return; > + } > + get_field_string_with_size(p, elem, "ivt", ivt_ascii, ivtlen); > + } > +} > + IMHO this code should be in parser/parser.c. The parserlib contains specific implementation for each parser, that is the parser type is solved to call the specific function for Json or libconfig. But we do not need a get_ivt_value() for both parser. Function should be moved. Best regards, Stefano > bool set_find_path(const char **nodes, const char *newpath, char **tmp) > { > char **paths; > diff --git a/include/parselib.h b/include/parselib.h > index b167470..cbf13c0 100644 > --- a/include/parselib.h > +++ b/include/parselib.h > @@ -84,6 +84,7 @@ void iterate_field(parsertype p, void *e, iterate_callback cb, void *data); > void get_field(parsertype p, void *e, const char *path, void *dest); > int exist_field_string(parsertype p, void *e, const char *path); > void get_hash_value(parsertype p, void *elem, unsigned char *hash); > +void get_ivt_value(parsertype p, void *elem, char *ivt_ascii); > void check_field_string(const char *src, char *dst, const size_t max_len); > void *find_root(parsertype p, void *root, const char **nodes); > void *get_node(parsertype p, void *root, const char **nodes); > diff --git a/parser/parser.c b/parser/parser.c > index 60f979a..bbabae5 100644 > --- a/parser/parser.c > +++ b/parser/parser.c > @@ -451,7 +451,7 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im > get_field(p, elem, "install-if-different", &image->id.install_if_different); > get_field(p, elem, "install-if-higher", &image->id.install_if_higher); > get_field(p, elem, "encrypted", &image->is_encrypted); > - GET_FIELD_STRING(p, elem, "ivt", image->ivt_ascii); > + get_ivt_value(p, elem, image->ivt_ascii); > > if (is_image_installed(&cfg->installed_sw_list, image)) { > image->skip = SKIP_SAME;
diff --git a/core/parsing_library.c b/core/parsing_library.c index 8d21683..dcb3b73 100644 --- a/core/parsing_library.c +++ b/core/parsing_library.c @@ -209,6 +209,21 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash) ascii_to_hash(hash, hash_ascii); } +void get_ivt_value(parsertype p, void *elem, char *ivt_ascii) +{ + size_t ivtlen; + const char *s = NULL; + s = get_field_string(p, elem, "ivt"); + if (s) { + ivtlen = strnlen(s, SWUPDATE_GENERAL_STRING_SIZE); + if (ivtlen != (AES_BLK_SIZE*2)) { + ERROR("Invalid ivt length"); + return; + } + get_field_string_with_size(p, elem, "ivt", ivt_ascii, ivtlen); + } +} + bool set_find_path(const char **nodes, const char *newpath, char **tmp) { char **paths; diff --git a/include/parselib.h b/include/parselib.h index b167470..cbf13c0 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -84,6 +84,7 @@ void iterate_field(parsertype p, void *e, iterate_callback cb, void *data); void get_field(parsertype p, void *e, const char *path, void *dest); int exist_field_string(parsertype p, void *e, const char *path); void get_hash_value(parsertype p, void *elem, unsigned char *hash); +void get_ivt_value(parsertype p, void *elem, char *ivt_ascii); void check_field_string(const char *src, char *dst, const size_t max_len); void *find_root(parsertype p, void *root, const char **nodes); void *get_node(parsertype p, void *root, const char **nodes); diff --git a/parser/parser.c b/parser/parser.c index 60f979a..bbabae5 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -451,7 +451,7 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im get_field(p, elem, "install-if-different", &image->id.install_if_different); get_field(p, elem, "install-if-higher", &image->id.install_if_higher); get_field(p, elem, "encrypted", &image->is_encrypted); - GET_FIELD_STRING(p, elem, "ivt", image->ivt_ascii); + get_ivt_value(p, elem, image->ivt_ascii); if (is_image_installed(&cfg->installed_sw_list, image)) { image->skip = SKIP_SAME;
Only set the image ivt_ascii if the size is valid. Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com> --- core/parsing_library.c | 15 +++++++++++++++ include/parselib.h | 1 + parser/parser.c | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-)