Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/tpm2_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,22 +1027,20 @@ bool tpm2_safe_read_from_stdin(int length, char *data) {
bool tpm2_pem_encoded_key_to_fingerprint(const char *pem_encoded_key,
char *fingerprint) {

bool is_pemkey_len_valid = strlen(pem_encoded_key) > 1024 ? false : true;
if (!is_pemkey_len_valid) {
if (strlen(pem_encoded_key) >= 1024) {
return false;
}

char str[1024] = "";
strcpy(str, pem_encoded_key);
strncpy(str, pem_encoded_key, 1023);
str[1023] = '\0';

/* walk through other tokens */
char base64[1024] = "";
char *token = strtok(str, "\n");
while ( token != NULL ) {
if (!strstr(token, "-----")) {
bool is_base64_overrun = (strlen(base64) + strlen(token)) > 1024 ?
true : false;
if (is_base64_overrun) {
if ((strlen(base64) + strlen(token)) >= 1024) {
return false;
}
strcat(base64, token);
Expand Down