Skip to content

Commit

Permalink
Fix reading 32-byte PIN from pin-source
Browse files Browse the repository at this point in the history
This commit closes #516 without causing an off-by-one error.
  • Loading branch information
mtrojnar committed Mar 5, 2024
1 parent 54fa261 commit 86a6332
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/eng_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 86a6332

Please sign in to comment.