@@ -604,6 +604,7 @@ static uint8_t *load_key(uint8_t **key_buffer, uint32_t *key_buffer_sz,
604604 }
605605 }
606606 fclose (f );
607+ f = NULL ;
607608 if (* key_buffer == NULL ) {
608609 printf ("Key buffer malloc error!\n" );
609610 goto failure ;
@@ -1443,6 +1444,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
14431444 printf ("Could not get certificate chain file size: %s\n" ,
14441445 strerror (errno ));
14451446 fclose (f );
1447+ f = NULL ;
14461448 goto failure ;
14471449 }
14481450
@@ -1457,19 +1459,22 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
14571459 cert_chain_sz ),
14581460 CMD .header_sz );
14591461 fclose (f );
1462+ f = NULL ;
14601463 goto failure ;
14611464 }
14621465
14631466 cert_chain = malloc (cert_chain_sz );
14641467 if (cert_chain == NULL ) {
14651468 printf ("Certificate chain buffer malloc error!\n" );
14661469 fclose (f );
1470+ f = NULL ;
14671471 goto failure ;
14681472 }
14691473
14701474 /* Read the entire file into the buffer */
14711475 io_sz = (int )fread (cert_chain , 1 , cert_chain_sz , f );
14721476 fclose (f );
1477+ f = NULL ;
14731478
14741479 if (io_sz != (int )cert_chain_sz ) {
14751480 printf ("Error reading certificate chain file: %s\n" ,
@@ -1774,6 +1779,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
17741779 }
17751780 io_sz = (int )fread (signature , 1 , CMD .signature_sz , f );
17761781 fclose (f );
1782+ f = NULL ;
17771783 if (io_sz <= 0 ) {
17781784 printf ("Error reading file %s\n" , CMD .signature_file );
17791785 goto failure ;
@@ -1821,13 +1827,15 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
18211827 if (io_sz != sizeof (uint32_t )) {
18221828 printf ("Error reading file %s\n" , CMD .policy_file );
18231829 fclose (f );
1830+ f = NULL ;
18241831 goto failure ;
18251832 }
18261833
18271834 if (!CMD .manual_sign ) {
18281835 /* in normal sign mode PCR digest (32 bytes) */
18291836 io_sz = (int )fread (digest , 1 , digest_sz , f );
18301837 fclose (f );
1838+ f = NULL ;
18311839 if (io_sz != (int )digest_sz ) {
18321840 printf ("Error reading file %s\n" , CMD .policy_file );
18331841 goto failure ;
@@ -1850,6 +1858,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
18501858 /* in manual mode remainder is PCR signature */
18511859 io_sz = (int )fread (policy , 1 , CMD .policy_sz , f );
18521860 fclose (f );
1861+ f = NULL ;
18531862 if (io_sz <= 0 ) {
18541863 printf ("Error reading file %s\n" , CMD .policy_file );
18551864 goto failure ;
@@ -1864,6 +1873,7 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
18641873 if (f != NULL ) {
18651874 fwrite (policy , 1 , CMD .policy_sz + sizeof (uint32_t ), f );
18661875 fclose (f );
1876+ f = NULL ;
18671877 }
18681878 }
18691879
0 commit comments