diff options
| author | 2026-03-17 14:33:12 +0100 | |
|---|---|---|
| committer | 2026-03-17 14:33:12 +0100 | |
| commit | e11cb70003e3fb3398bc641439740bb83f5de8f0 (patch) | |
| tree | 4aef4c6cf97c999748c70063cf8c8a6c4b480c3e /xs_openssl.h | |
| parent | Call ulimit -n to increase file descriptors in examples/snac_netbsd. (diff) | |
| download | snac2-e11cb70003e3fb3398bc641439740bb83f5de8f0.tar.gz snac2-e11cb70003e3fb3398bc641439740bb83f5de8f0.tar.xz snac2-e11cb70003e3fb3398bc641439740bb83f5de8f0.zip | |
fix: memory leak and oob read in "adduser"
Diffstat (limited to 'xs_openssl.h')
| -rw-r--r-- | xs_openssl.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/xs_openssl.h b/xs_openssl.h index 64b59dd..4bc14d2 100644 --- a/xs_openssl.h +++ b/xs_openssl.h | |||
| @@ -38,7 +38,7 @@ xs_str *xs_base64_enc(const xs_val *data, int sz) | |||
| 38 | { | 38 | { |
| 39 | BIO *mem, *b64; | 39 | BIO *mem, *b64; |
| 40 | BUF_MEM *bptr; | 40 | BUF_MEM *bptr; |
| 41 | 41 | ||
| 42 | b64 = BIO_new(BIO_f_base64()); | 42 | b64 = BIO_new(BIO_f_base64()); |
| 43 | mem = BIO_new(BIO_s_mem()); | 43 | mem = BIO_new(BIO_s_mem()); |
| 44 | b64 = BIO_push(b64, mem); | 44 | b64 = BIO_push(b64, mem); |
| @@ -118,7 +118,7 @@ xs_dict *xs_evp_genkey(int bits) | |||
| 118 | /* generates an RSA keypair using the EVP interface */ | 118 | /* generates an RSA keypair using the EVP interface */ |
| 119 | { | 119 | { |
| 120 | xs_dict *keypair = NULL; | 120 | xs_dict *keypair = NULL; |
| 121 | EVP_PKEY_CTX *ctx; | 121 | EVP_PKEY_CTX *ctx = NULL; |
| 122 | EVP_PKEY *pkey = NULL; | 122 | EVP_PKEY *pkey = NULL; |
| 123 | 123 | ||
| 124 | if ((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL)) == NULL) | 124 | if ((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL)) == NULL) |
| @@ -142,12 +142,17 @@ xs_dict *xs_evp_genkey(int bits) | |||
| 142 | 142 | ||
| 143 | keypair = xs_dict_new(); | 143 | keypair = xs_dict_new(); |
| 144 | 144 | ||
| 145 | keypair = xs_dict_append(keypair, "secret", sptr->data); | 145 | xs *secret = xs_str_new_sz(sptr->data, sptr->length); |
| 146 | keypair = xs_dict_append(keypair, "public", pptr->data); | 146 | xs *public = xs_str_new_sz(pptr->data, pptr->length); |
| 147 | keypair = xs_dict_append(keypair, "secret", secret); | ||
| 148 | keypair = xs_dict_append(keypair, "public", public); | ||
| 147 | 149 | ||
| 148 | BIO_free(bs); | 150 | BIO_free(bs); |
| 149 | BIO_free(bp); | 151 | BIO_free(bp); |
| 150 | 152 | ||
| 153 | EVP_PKEY_free(pkey); | ||
| 154 | EVP_PKEY_CTX_free(ctx); | ||
| 155 | |||
| 151 | end: | 156 | end: |
| 152 | return keypair; | 157 | return keypair; |
| 153 | } | 158 | } |