-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reading 32-byte PIN from pin-source
This commit closes #516 without causing an off-by-one error.
- Loading branch information
Showing
1 changed file
with
8 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Copyright (c) 2002 Juha Yrjölä | ||
* Copyright (c) 2002 Olaf Kirch | ||
* Copyright (c) 2003 Kevin Stefanik | ||
* Copyright (c) 2016-2017 Michał Trojnara <[email protected]> | ||
* Copyright (c) 2016-2024 Michał Trojnara <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
|
@@ -271,17 +271,22 @@ static int read_from_file(ENGINE_CTX *ctx, | |
const char *path, char *field, size_t *field_len) | ||
{ | ||
BIO *fp; | ||
char *txt; | ||
|
||
fp = BIO_new_file(path, "r"); | ||
if (!fp) { | ||
ctx_log(ctx, 0, "Could not open file %s\n", path); | ||
return 0; | ||
} | ||
if (BIO_gets(fp, field, *field_len) > 0) { | ||
*field_len = strlen(field); | ||
|
||
txt = OPENSSL_malloc(*field_len + 1); /* + 1 for '\0' */ | ||
if (BIO_gets(fp, txt, *field_len + 1) > 0) { | ||
memcpy(field, txt, *field_len); | ||
*field_len = strlen(txt); | ||
} else { | ||
*field_len = 0; | ||
} | ||
OPENSSL_free(txt); | ||
|
||
BIO_free(fp); | ||
return 1; | ||
|