diff options
| -rw-r--r-- | src/irmd/oap/tests/oap_test.c | 16 | ||||
| -rw-r--r-- | src/lib/crypt/openssl.c | 16 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/irmd/oap/tests/oap_test.c b/src/irmd/oap/tests/oap_test.c index 70943d7c..70f0a248 100644 --- a/src/irmd/oap/tests/oap_test.c +++ b/src/irmd/oap/tests/oap_test.c @@ -245,14 +245,13 @@ static int test_oap_piggyback_data(void) /* Set server's response data (ctx.data will take cli data) */ srv_data.len = strlen(srv_data_str); - srv_data.data = malloc(srv_data.len); - if (srv_data.data == NULL) - goto fail_cleanup; - memcpy(srv_data.data, srv_data_str, srv_data.len); + srv_data.data = (uint8_t *) srv_data_str; freebuf(ctx.data); - ctx.data = srv_data; - clrbuf(srv_data); + ctx.data.data = srv_data.data; + ctx.data.len = srv_data.len; + srv_data.data = NULL; + srv_data.len = 0; if (oap_srv_process_ctx(&ctx) < 0) goto fail_cleanup; @@ -276,6 +275,11 @@ static int test_oap_piggyback_data(void) goto fail_cleanup; } + /* Free the copied data */ + free(ctx.data.data); + ctx.data.data = NULL; + ctx.data.len = 0; + if (memcmp(ctx.cli.key, ctx.srv.key, SYMMKEYSZ) != 0) { printf("Client and server keys do not match!\n"); goto fail_cleanup; diff --git a/src/lib/crypt/openssl.c b/src/lib/crypt/openssl.c index 71a69c1c..638da209 100644 --- a/src/lib/crypt/openssl.c +++ b/src/lib/crypt/openssl.c @@ -1213,21 +1213,19 @@ int openssl_load_pubkey_file_to_der(const char * path, if (pkey == NULL) goto fail_key; - fclose(fp); - /* Extract public key bytes in DER format */ ret = get_pk_bytes_from_key(pkey, buf); + if (ret < 0) + goto fail_extract; EVP_PKEY_free(pkey); - if (ret < 0) - goto fail_extract; + fclose(fp); return 0; fail_extract: - clrbuf(*buf); - return -1; + EVP_PKEY_free(pkey); fail_key: fclose(fp); fail_file: @@ -1295,6 +1293,7 @@ int openssl_load_pubkey_raw_file(const char * path, memcpy(buf->data, tmp_buf, bytes_read); buf->len = bytes_read; + fclose(fp); return 0; fail_malloc: @@ -1337,8 +1336,6 @@ int openssl_load_privkey_raw_file(const char * path, goto fail_file; bytes_read = fread(tmp_buf, 1, sizeof(tmp_buf), fp); - fclose(fp); - if (bytes_read == 0) goto fail_read; @@ -1355,11 +1352,14 @@ int openssl_load_privkey_raw_file(const char * path, if (pkey == NULL) goto fail_read; + fclose(fp); + *key = (void *) pkey; return 0; fail_read: + fclose(fp); fail_file: *key = NULL; return -1; |
