Skip to content

Commit

Permalink
tool: check length before trying to store cert in buffer
Browse files Browse the repository at this point in the history
fixes #148
  • Loading branch information
klali committed Aug 16, 2018
1 parent 16d5390 commit 45e74cf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tool/yubico-piv-tool.c
Expand Up @@ -561,6 +561,12 @@ static bool import_cert(ykpiv_state *state, enum enum_key_format cert_format,
unsigned char certdata[YKPIV_OBJ_MAX_SIZE];
unsigned char *certptr = certdata;
ykpiv_rc res;

if(cert_len > YKPIV_OBJ_MAX_SIZE) {
fprintf(stderr, "Length of certificate is more than can fit.\n");
goto import_cert_out;
}

if (compress) {
if (fread(certdata, 1, (size_t)cert_len, input_file) != (size_t)cert_len) {
fprintf(stderr, "Failed to read compressed certificate\n");
Expand Down

0 comments on commit 45e74cf

Please sign in to comment.