diff options
| author | 2026-03-17 20:00:08 +0100 | |
|---|---|---|
| committer | 2026-03-17 20:00:08 +0100 | |
| commit | 192655ed640346d40590b62b007b7ed188b368e2 (patch) | |
| tree | 221862d1b70828ef1b61031e130d982229a50baf | |
| parent | Merge pull request 'Fixed missing `id` attribute in `html_checkbox()`' (#585)... (diff) | |
| parent | fix: memory leak and oob read in "adduser" (diff) | |
| download | snac2-192655ed640346d40590b62b007b7ed188b368e2.tar.gz snac2-192655ed640346d40590b62b007b7ed188b368e2.tar.xz snac2-192655ed640346d40590b62b007b7ed188b368e2.zip | |
Merge pull request 'Fixed buffer overflow read in `xs_evp_genkey()` when creating a new user' (#583) from dandelions/snac2:pr-adduser-leak into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/583
| -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 | } |