Checks on errors for ftell and fseek

This commit is contained in:
Frank Morgner 2015-09-17 20:40:02 +02:00
parent b5de72fe13
commit 59254d9d88
1 changed files with 10 additions and 2 deletions

View File

@ -1450,9 +1450,17 @@ static int piv_get_key(sc_card_t *card, unsigned int alg_id, u8 **key, size_t *l
goto err;
}
fseek(f, 0L, SEEK_END);
if (0 > fseek(f, 0L, SEEK_END))
r = SC_ERROR_INTERNAL;
fsize = ftell(f);
fseek(f, 0L, SEEK_SET);
if (0 > (long) fsize)
r = SC_ERROR_INTERNAL;
if (0 > fseek(f, 0L, SEEK_SET))
r = SC_ERROR_INTERNAL;
if(r) {
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Could not read %s\n", keyfilename);
goto err;
}
keybuf = malloc(fsize+1); /* if not binary, need null to make it a string */
if (!keybuf) {