Skip to content

Commit

Permalink
Get rid of hardcoded MAX_VALUE_LEN
Browse files Browse the repository at this point in the history
Fix #513
  • Loading branch information
mtrojnar committed Oct 5, 2023
1 parent b3d101e commit dd0a8c6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/eng_back.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

/* The maximum length of an internally-allocated PIN */
#define MAX_PIN_LENGTH 32
#define MAX_VALUE_LEN 200

struct st_engine_ctx {
/* Engine configuration */
Expand Down Expand Up @@ -378,8 +377,8 @@ static void *ctx_try_load_object(ENGINE_CTX *ctx,
PKCS11_SLOT *found_slot = NULL, **matched_slots = NULL;
PKCS11_TOKEN *tok, *match_tok = NULL;
unsigned int n, m;
unsigned char obj_id[MAX_VALUE_LEN / 2];
size_t obj_id_len = sizeof(obj_id);
unsigned char *obj_id = NULL;
size_t obj_id_len = 0;
char *obj_label = NULL;
char tmp_pin[MAX_PIN_LENGTH+1];
size_t tmp_pin_len = MAX_PIN_LENGTH;
Expand All @@ -389,6 +388,8 @@ static void *ctx_try_load_object(ENGINE_CTX *ctx,
void *object = NULL;

if (object_uri && *object_uri) {
obj_id_len = strlen(object_uri) + 1;
obj_id = OPENSSL_malloc(obj_id_len);
if (!strncasecmp(object_uri, "pkcs11:", 7)) {
n = parse_pkcs11_uri(ctx, object_uri, &match_tok,
obj_id, &obj_id_len, tmp_pin, &tmp_pin_len, &obj_label);
Expand Down Expand Up @@ -585,6 +586,8 @@ static void *ctx_try_load_object(ENGINE_CTX *ctx,
OPENSSL_free(obj_label);
if (matched_slots)
free(matched_slots);
if (obj_id)
OPENSSL_free(obj_id);
return object;
}

Expand Down

0 comments on commit dd0a8c6

Please sign in to comment.