mirror of
https://github.com/ipxe/ipxe
synced 2026-01-22 20:19:08 +03:00
[image] Add the concept of a static image
Not all images are allocated via alloc_image(). For example: embedded images, the static images created to hold a runtime command line, and the images used by unit tests are all static structures. Using image_set_cmdline() (via e.g. the "imgargs" command) to set the command-line arguments of a static image will succeed but will leak memory, since nothing will ever free the allocated command line. There are no code paths that can lead to calling image_set_len() on a static image, but there is no safety check against future code paths attempting this. Define a flag IMAGE_STATIC to mark an image as statically allocated, generalise free_image() to also handle freeing dynamically allocated portions of static images (such as the command line), and expose free_image() for use by static images. Define a related flag IMAGE_STATIC_NAME to mark the name as statically allocated. Allow a statically allocated name to be replaced with a dynamically allocated name since this is a potentially valid use case (e.g. if "imgdecrypt --name <name>" is used on an embedded image). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -46,6 +46,7 @@ struct asn1_test {
|
||||
static struct image _name ## __image = { \
|
||||
.refcnt = REF_INIT ( ref_no_free ), \
|
||||
.name = #_name, \
|
||||
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
|
||||
.data = ( userptr_t ) ( _name ## __file ), \
|
||||
.len = sizeof ( _name ## __file ), \
|
||||
}; \
|
||||
|
||||
@@ -85,6 +85,7 @@ struct cms_test_keypair {
|
||||
.image = { \
|
||||
.refcnt = REF_INIT ( ref_no_free ), \
|
||||
.name = #NAME, \
|
||||
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
|
||||
.data = ( userptr_t ) ( NAME ## _data ), \
|
||||
.len = sizeof ( NAME ## _data ), \
|
||||
}, \
|
||||
@@ -97,6 +98,7 @@ struct cms_test_keypair {
|
||||
.image = { \
|
||||
.refcnt = REF_INIT ( ref_no_free ), \
|
||||
.name = #NAME, \
|
||||
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
|
||||
.data = ( userptr_t ) ( NAME ## _data ), \
|
||||
.len = sizeof ( NAME ## _data ), \
|
||||
}, \
|
||||
@@ -109,6 +111,7 @@ struct cms_test_keypair {
|
||||
.image = { \
|
||||
.refcnt = REF_INIT ( ref_no_free ), \
|
||||
.name = #NAME, \
|
||||
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
|
||||
.type = &der_image_type, \
|
||||
.data = ( userptr_t ) ( NAME ## _data ), \
|
||||
.len = sizeof ( NAME ## _data ), \
|
||||
|
||||
@@ -41,6 +41,7 @@ struct pixel_buffer_test {
|
||||
static struct image _name ## __image = { \
|
||||
.refcnt = REF_INIT ( ref_no_free ), \
|
||||
.name = #_name, \
|
||||
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
|
||||
.data = ( userptr_t ) ( _name ## __file ), \
|
||||
.len = sizeof ( _name ## __file ), \
|
||||
}; \
|
||||
|
||||
@@ -162,6 +162,7 @@ static struct image_type test_image_type = {
|
||||
static struct image test_image = {
|
||||
.refcnt = REF_INIT ( ref_no_free ),
|
||||
.name = "<TESTS>",
|
||||
.flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ),
|
||||
.type = &test_image_type,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user