[PATCH] Fix broken CPIO from last commit

16 views
Skip to first unread message

Stefano Babic

unread,
Jun 7, 2017, 2:03:57 PM6/7/17
to swup...@googlegroups.com, Stefano Babic, Sid-Ali Teir, Georges Savoundararadj, Romain Bazile
Commit 93f9b1972676a53ee7a8a44f5b069b04a3c2ed57 introduces a bug if the
new attribute "offset" is not set. In fact, it retrieves the value with
GET_FIELD_STRING, but this function does not touch the destination if no
attribute is found.
Initialize the attribute with an empty string before retrieving the
field.

Signed-off-by: Stefano Babic <sba...@denx.de>
CC: Sid-Ali Teir <st...@witekio.us>
CC: Georges Savoundararadj <gsavoun...@witekio.us>
CC: Romain Bazile <romain...@ubiant.com>
---
parser/parser.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/parser/parser.c b/parser/parser.c
index 2fc9a4f..6ad9741 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -388,6 +388,12 @@ static void parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
return;
}

+ /*
+ * GET_FIELD_STRING does not touch the passed string if it is not
+ * found, be sure that it is empty
+ */
+ seek_str[0] = '\0';
+
GET_FIELD_STRING(p, elem, "name", image->id.name);
GET_FIELD_STRING(p, elem, "version", image->id.version);
GET_FIELD_STRING(p, elem, "filename", image->fname);
--
2.7.4

Georges Savoundararadj

unread,
Jun 7, 2017, 2:39:32 PM6/7/17
to Stefano Babic, swup...@googlegroups.com, Sid-Ali Teir, Romain Bazile
Reviewed-by: Georges Savoundararadj <gsavoun...@witekio.us>

Thanks,

Georges

Sid-Ali TEIR

unread,
Jun 7, 2017, 5:25:58 PM6/7/17
to Georges Savoundararadj, Stefano Babic, swup...@googlegroups.com, Romain Bazile
Hi Stefano,

This should also be done in parser_external.c just in case, what do you
think ?

Thanks,

Sid-Ali.

Stefano Babic

unread,
Jun 8, 2017, 4:16:37 AM6/8/17
to Sid-Ali TEIR, Georges Savoundararadj, Stefano Babic, swup...@googlegroups.com, Romain Bazile
Hi Sid-Ali,

On 07/06/2017 23:25, Sid-Ali TEIR wrote:
> Hi Stefano,
>
> This should also be done in parser_external.c just in case, what do you
> think ?
>

IMHO this issue is not present with the external parser. In fact, there
is a block before accessing the temporary seek_str on the stack:

82 if (!strncmp(key, offset, sizeof(offset))) {
83 strncpy(seek_str, value,

If no "offset" attribute is set, the check fails and the rest of the
code does not run - it does not matter if seek_str is initialized,
because it is not evaluated. We are sure that img->seek is zero because,
from design, calloc() is used for any new allocated image, and this
guarantees that the structure is zeroed.

Best regards,
Stefano
--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Sid-Ali TEIR

unread,
Jun 8, 2017, 12:41:27 PM6/8/17
to Stefano Babic, Georges Savoundararadj, swup...@googlegroups.com, Romain Bazile
Sounds good.

Reviewed-by: Sid-Ali Teir <st...@witekio.us>

Thanks,

Sid-Ali.
Reply all
Reply to author
Forward
0 new messages