@@ -509,10 +509,10 @@ int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset)
return 0;
}
-off_t extract_sw_description(int fd, const char *descfile, off_t start)
+int extract_sw_description(int fd, const char *descfile, off_t *offs)
{
struct filehdr fdh;
- unsigned long offset = start;
+ unsigned long offset = *offs;
char output_file[64];
uint32_t checksum;
int fdout;
@@ -562,7 +562,9 @@ off_t extract_sw_description(int fd, const char *descfile, off_t start)
return -1;
}
- return offset;
+ *offs = offset;
+
+ return 0;
}
int extract_img_from_cpio(int fd, unsigned long offset, struct filehdr *fdh)
@@ -299,11 +299,19 @@ static int install_from_file(char *fname, int check)
}
}
- pos = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME, 0);
+ pos = 0;
+ ret = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME, &pos);
#ifdef CONFIG_SIGNED_IMAGES
- pos = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME ".sig",
- pos);
+ ret = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME ".sig",
+ &pos);
#endif
+ /*
+ * Check if files could be extracted
+ */
+ if (ret) {
+ ERROR("Failed to extract meta information");
+ exit(1);
+ }
char* swdescfilename = alloca(strlen(get_tmpdir())+strlen(SW_DESCRIPTION_FILENAME)+1);
sprintf(swdescfilename, "%s%s", get_tmpdir(), SW_DESCRIPTION_FILENAME);
@@ -150,7 +150,6 @@ struct swupdate_cfg {
} \
} while(0)
-off_t extract_sw_description(int fd, const char *descfile, off_t start);
int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start);
struct swupdate_cfg *get_swupdate_cfg(void);
void free_image(struct img_type *img);
@@ -139,7 +139,7 @@ int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs,
int skip_file, int compressed, uint32_t *checksum,
unsigned char *hash, int encrypted, writeimage callback);
int copyimage(void *out, struct img_type *img, writeimage callback);
-off_t extract_sw_description(int fd, const char *descfile, off_t start);
+int extract_sw_description(int fd, const char *descfile, off_t *offs);
off_t extract_next_file(int fd, int fdout, off_t start, int compressed,
int encrypted, unsigned char *hash);
int openfileoutput(const char *filename);
The -c (check) option verifies sw-description and signature. However, it does not check if the files are correctly extracted before verifying. If files were already extracted by a previous run, the result can still be successful even if the SWU is completely wrong. This does not happen in case of network install because files are cleaned up after run. Check that the extraction of sw-description and sw-description.sig is successful before parsing them. Signed-off-by: Stefano Babic <sbabic@denx.de> Reported-by: Karim Lazhard <karim.lazhard@gmail.com> --- core/cpio_utils.c | 8 +++++--- core/swupdate.c | 14 +++++++++++--- include/swupdate.h | 1 - include/util.h | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-)