image: always parse image regions
Rather than only calling image_find_regions when we want to sign or verify image, call it when the image is loaded. We'll want to use the parse data later, which will require it to be present on all instances of an image. Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
parent
36a14ed978
commit
8a55df5e96
4 changed files with 30 additions and 31 deletions
56
image.c
56
image.c
|
@ -227,31 +227,6 @@ static int image_pecoff_parse(struct image *image)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct image *image_load(const char *filename)
|
||||
{
|
||||
struct image *image;
|
||||
int rc;
|
||||
|
||||
image = talloc(NULL, struct image);
|
||||
if (!image) {
|
||||
perror("talloc(image)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fileio_read_file(image, filename, &image->buf, &image->size);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
rc = image_pecoff_parse(image);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
return image;
|
||||
err:
|
||||
talloc_free(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int align_up(int size, int align)
|
||||
{
|
||||
return (size + align - 1) & ~(align - 1);
|
||||
|
@ -274,7 +249,7 @@ static void set_region_from_range(struct region *region, void *start, void *end)
|
|||
region->size = end - start;
|
||||
}
|
||||
|
||||
int image_find_regions(struct image *image)
|
||||
static int image_find_regions(struct image *image)
|
||||
{
|
||||
struct region *regions;
|
||||
void *buf = image->buf;
|
||||
|
@ -391,6 +366,35 @@ int image_find_regions(struct image *image)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct image *image_load(const char *filename)
|
||||
{
|
||||
struct image *image;
|
||||
int rc;
|
||||
|
||||
image = talloc(NULL, struct image);
|
||||
if (!image) {
|
||||
perror("talloc(image)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fileio_read_file(image, filename, &image->buf, &image->size);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
rc = image_pecoff_parse(image);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
rc = image_find_regions(image);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
return image;
|
||||
err:
|
||||
talloc_free(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int image_hash_sha256(struct image *image, uint8_t digest[])
|
||||
{
|
||||
struct region *region;
|
||||
|
|
1
image.h
1
image.h
|
@ -98,7 +98,6 @@ struct cert_table_header {
|
|||
|
||||
struct image *image_load(const char *filename);
|
||||
|
||||
int image_find_regions(struct image *image);
|
||||
int image_hash_sha256(struct image *image, uint8_t digest[]);
|
||||
int image_add_signature(struct image *, void *sig, int size);
|
||||
void image_remove_signature(struct image *image);
|
||||
|
|
2
sbsign.c
2
sbsign.c
|
@ -180,8 +180,6 @@ int main(int argc, char **argv)
|
|||
|
||||
talloc_steal(ctx, ctx->image);
|
||||
|
||||
image_find_regions(ctx->image);
|
||||
|
||||
ERR_load_crypto_strings();
|
||||
OpenSSL_add_all_digests();
|
||||
OpenSSL_add_all_ciphers();
|
||||
|
|
|
@ -198,8 +198,6 @@ int main(int argc, char **argv)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
image_find_regions(image);
|
||||
|
||||
if (detached_sig_filename)
|
||||
rc = load_detached_signature_data(image, detached_sig_filename,
|
||||
&sig_buf, &sig_size);
|
||||
|
|
Loading…
Reference in a new issue