From 6bae4cb59b28442348876b12a7a9598460282952 Mon Sep 17 00:00:00 2001 From: Aveen Ismail Date: Thu, 5 Sep 2024 15:33:21 +0200 Subject: [PATCH] Code optimization --- common/util.c | 1 + src/commands.c | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/common/util.c b/common/util.c index ed5f696f..874a4646 100644 --- a/common/util.c +++ b/common/util.c @@ -385,6 +385,7 @@ bool read_public_key(uint8_t *buf, size_t len, yh_algorithm *algo, } if(BIO_write(bio, buf, len) <= 0) { + BIO_free_all(bio); return false; } diff --git a/src/commands.c b/src/commands.c index 1ed5dc43..1c35e665 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1170,7 +1170,6 @@ int yh_com_get_pubkey(yubihsm_context *ctx, Argument *argv, cmd_format in_fmt, if (BIO_flush(bio) != 1) { fprintf(stderr, "Unable to flush BIO\n"); BIO_free_all(b64); - BIO_free_all(bio); error = true; goto getpk_base64_cleanup; } @@ -1269,7 +1268,6 @@ int yh_com_get_device_pubkey(yubihsm_context *ctx, Argument *argv, if (BIO_flush(bio) != 1) { fprintf(stderr, "Unable to flush BIO\n"); BIO_free_all(b64); - BIO_free_all(bio); error = true; goto getdpk_base64_cleanup; } @@ -3098,7 +3096,6 @@ int yh_com_sign_ssh_certificate(yubihsm_context *ctx, Argument *argv, uint8_t data[YH_MSG_BUF_SIZE + 1024] = {0}; size_t response_len = sizeof(data); - size_t in_len = 4 + 256; // 4 bytes time stamp + 256 bytes signature if (argv[4].len > YH_MSG_BUF_SIZE) { fprintf(stderr, "Failed to sign ssh certificate: %s\n", @@ -3135,7 +3132,8 @@ int yh_com_sign_ssh_certificate(yubihsm_context *ctx, Argument *argv, int ret = 0; (void) BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); - if (BIO_write(bio, data + in_len, argv[4].len + response_len - in_len) <= 0) { + if (BIO_write(bio, data + 4 + 256, argv[4].len + response_len - 4 - 256) <= + 0) { // TODO(adma): FIXME, unmagify fprintf(stderr, "Failed to sign SSH certificate.\n"); ret = -1; goto clean_bio;