File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change 11
11
#include <string.h>
12
12
#include <errno.h>
13
13
#include <endian.h>
14
+ #include <assert.h>
14
15
15
16
#include <linux/bootconfig.h>
16
17
@@ -363,7 +364,12 @@ static int delete_xbc(const char *path)
363
364
364
365
static int apply_xbc (const char * path , const char * xbc_path )
365
366
{
366
- char * buf , * data , * p ;
367
+ struct {
368
+ uint32_t size ;
369
+ uint32_t csum ;
370
+ char magic [BOOTCONFIG_MAGIC_LEN ];
371
+ } footer ;
372
+ char * buf , * data ;
367
373
size_t total_size ;
368
374
struct stat stat ;
369
375
const char * msg ;
@@ -433,17 +439,13 @@ static int apply_xbc(const char *path, const char *xbc_path)
433
439
size += pad ;
434
440
435
441
/* Add a footer */
436
- p = data + size ;
437
- * (uint32_t * )p = htole32 (size );
438
- p += sizeof (uint32_t );
442
+ footer .size = htole32 (size );
443
+ footer .csum = htole32 (csum );
444
+ memcpy (footer .magic , BOOTCONFIG_MAGIC , BOOTCONFIG_MAGIC_LEN );
445
+ static_assert (sizeof (footer ) == BOOTCONFIG_FOOTER_SIZE );
446
+ memcpy (data + size , & footer , BOOTCONFIG_FOOTER_SIZE );
439
447
440
- * (uint32_t * )p = htole32 (csum );
441
- p += sizeof (uint32_t );
442
-
443
- memcpy (p , BOOTCONFIG_MAGIC , BOOTCONFIG_MAGIC_LEN );
444
- p += BOOTCONFIG_MAGIC_LEN ;
445
-
446
- total_size = p - data ;
448
+ total_size = size + BOOTCONFIG_FOOTER_SIZE ;
447
449
448
450
ret = write (fd , data , total_size );
449
451
if (ret < total_size ) {
You can’t perform that action at this time.
0 commit comments