make sure size_t doesnt overflow an int

This commit is contained in:
iceman1001 2022-07-04 18:49:30 +02:00
commit c08c2dcf3a

View file

@ -716,7 +716,8 @@ static const uint8_t jpeg_header[4] = { 0xFF, 0xD8, 0xFF, 0xE0 };
static const uint8_t jpeg2k_header[6] = { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50 }; static const uint8_t jpeg2k_header[6] = { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50 };
static int emrtd_dump_ef_dg2(uint8_t *file_contents, size_t file_length, const char *path) { static int emrtd_dump_ef_dg2(uint8_t *file_contents, size_t file_length, const char *path) {
int offset, datalen = 0; size_t offset;
int datalen = 0;
// This is a hacky impl that just looks for the image header. I'll improve it eventually. // This is a hacky impl that just looks for the image header. I'll improve it eventually.
// based on mrpkey.py // based on mrpkey.py
@ -738,6 +739,7 @@ static int emrtd_dump_ef_dg2(uint8_t *file_contents, size_t file_length, const c
char *filepath = calloc(strlen(path) + 100, sizeof(char)); char *filepath = calloc(strlen(path) + 100, sizeof(char));
if (filepath == NULL) if (filepath == NULL)
return PM3_EMALLOC; return PM3_EMALLOC;
strcpy(filepath, path); strcpy(filepath, path);
strncat(filepath, PATHSEP, 2); strncat(filepath, PATHSEP, 2);
strcat(filepath, dg_table[EF_DG2].filename); strcat(filepath, dg_table[EF_DG2].filename);