summaryrefslogtreecommitdiff
path: root/extra/usb_updater/desc_parser.c
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2018-03-06 11:31:08 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-03-15 17:58:20 -0700
commitccbba8f968ac4bf77c7c8ed665ab96a587f65ff8 (patch)
tree8c38402a6d04e384aa570fd239c7139567e18989 /extra/usb_updater/desc_parser.c
parent9e95ac3e0aeeaa12aaca75bdb73a055ab969e310 (diff)
downloadchrome-ec-ccbba8f968ac4bf77c7c8ed665ab96a587f65ff8.tar.gz
gsctool: require exactly two hash sections for every board
The same Chrome OS device could have not only several released firmware images, but also several variations of the GBB contents. Any permutation of these two sets is possible, but both areas must match, as modified GBB is no smaller problem than modified code or RO data. With this patch the verifier will continue looking for board sections in the descriptors database until the entire database has been scanned. Only finding exactly two sections, and each section providing proper matches will qualify the check as 'pass'. BRANCH=none BUG=b:73668125 TEST=verified that both single and dual section descriptions are processed properly, and that matching 1 and 3 sections triggers a return error. Change-Id: I181655192246ce245c43e6ce7ba4768ac5c9e51a Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/951864 Reviewed-by: Andrey Pronin <apronin@chromium.org>
Diffstat (limited to 'extra/usb_updater/desc_parser.c')
-rw-r--r--extra/usb_updater/desc_parser.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/extra/usb_updater/desc_parser.c b/extra/usb_updater/desc_parser.c
index 6570c5f23e..5bd996bdda 100644
--- a/extra/usb_updater/desc_parser.c
+++ b/extra/usb_updater/desc_parser.c
@@ -18,6 +18,12 @@ static FILE *hash_file_;
static int line_count_;
static int section_count_;
+/*
+ * This is used to verify consistency of the description database, namely that
+ * all hash sections include the same number of hash variants.
+ */
+static size_t variant_count;
+
/* Size of the retrieved string or negative OS error value. */
static ssize_t get_next_line(char *next_line, size_t line_size)
{
@@ -239,13 +245,6 @@ int parser_get_next_range(struct addr_range **range)
int rv;
/*
- * This is used to verify consistency of the description database,
- * namely that all hash sections include the same numger of hash
- * variants.
- */
- static size_t variant_count;
-
- /*
* We come here after hash descriptor database file was opened and the
* current board's section has been found. Just in case check if the
* file has been opened.
@@ -308,11 +307,13 @@ int parser_find_board(const char *hash_file_name, const char *board_id)
char next_line[1000]; /* Should be enough for the largest descriptor. */
ssize_t id_len = strlen(board_id);
- hash_file_ = fopen(hash_file_name, "r");
if (!hash_file_) {
- fprintf(stderr, "Error:%s can not open file '%s'\n",
- strerror(errno), hash_file_name);
- return errno;
+ hash_file_ = fopen(hash_file_name, "r");
+ if (!hash_file_) {
+ fprintf(stderr, "Error:%s can not open file '%s'\n",
+ strerror(errno), hash_file_name);
+ return errno;
+ }
}
while (1) {
@@ -320,18 +321,17 @@ int parser_find_board(const char *hash_file_name, const char *board_id)
entry_size = get_next_line(next_line, sizeof(next_line));
if (entry_size < 0) {
- fclose(hash_file_);
return entry_size;
}
if ((entry_size == id_len) &&
- !memcmp(next_line, board_id, id_len))
+ !memcmp(next_line, board_id, id_len)) {
+ variant_count = 0;
return 0;
+ }
}
- fclose(hash_file_);
- hash_file_ = NULL;
- return errno;
+ return -ENODATA;
}
void parser_done(void)