1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-30 13:01:23 +03:00

pki_container_openssh: Use SSH_BUFFER_FREE()

Fixes T183

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Andreas Schneider
2019-10-31 09:41:09 +01:00
parent f422fb02f6
commit d7abfe7e8f

View File

@@ -159,7 +159,7 @@ static int pki_private_key_decrypt(ssh_string blob,
if (rc != SSH_ERROR){ if (rc != SSH_ERROR){
rc = ssh_buffer_unpack(buffer, "Sd", &salt, &rounds); rc = ssh_buffer_unpack(buffer, "Sd", &salt, &rounds);
} }
ssh_buffer_free(buffer); SSH_BUFFER_FREE(buffer);
if (rc == SSH_ERROR){ if (rc == SSH_ERROR){
return SSH_ERROR; return SSH_ERROR;
} }
@@ -364,11 +364,11 @@ ssh_pki_openssh_import(const char *text_key,
} }
out: out:
if (buffer != NULL) { if (buffer != NULL) {
ssh_buffer_free(buffer); SSH_BUFFER_FREE(buffer);
buffer = NULL; buffer = NULL;
} }
if (privkey_buffer != NULL) { if (privkey_buffer != NULL) {
ssh_buffer_free(privkey_buffer); SSH_BUFFER_FREE(privkey_buffer);
privkey_buffer = NULL; privkey_buffer = NULL;
} }
SAFE_FREE(magic); SAFE_FREE(magic);
@@ -620,26 +620,26 @@ ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
salt = ssh_string_new(16); salt = ssh_string_new(16);
if (salt == NULL){ if (salt == NULL){
ssh_buffer_free(kdf_buf); SSH_BUFFER_FREE(kdf_buf);
goto error; goto error;
} }
ok = ssh_get_random(ssh_string_data(salt), 16, 0); ok = ssh_get_random(ssh_string_data(salt), 16, 0);
if (!ok) { if (!ok) {
ssh_buffer_free(kdf_buf); SSH_BUFFER_FREE(kdf_buf);
goto error; goto error;
} }
ssh_buffer_pack(kdf_buf, "Sd", salt, rounds); ssh_buffer_pack(kdf_buf, "Sd", salt, rounds);
kdf_options = ssh_string_new(ssh_buffer_get_len(kdf_buf)); kdf_options = ssh_string_new(ssh_buffer_get_len(kdf_buf));
if (kdf_options == NULL){ if (kdf_options == NULL){
ssh_buffer_free(kdf_buf); SSH_BUFFER_FREE(kdf_buf);
goto error; goto error;
} }
memcpy(ssh_string_data(kdf_options), memcpy(ssh_string_data(kdf_options),
ssh_buffer_get(kdf_buf), ssh_buffer_get(kdf_buf),
ssh_buffer_get_len(kdf_buf)); ssh_buffer_get_len(kdf_buf));
ssh_buffer_free(kdf_buf); SSH_BUFFER_FREE(kdf_buf);
rc = pki_private_key_encrypt(privkey_buffer, rc = pki_private_key_encrypt(privkey_buffer,
passphrase, passphrase,
"aes128-cbc", "aes128-cbc",
@@ -709,13 +709,13 @@ error:
if (privkey_buffer != NULL) { if (privkey_buffer != NULL) {
void *bufptr = ssh_buffer_get(privkey_buffer); void *bufptr = ssh_buffer_get(privkey_buffer);
explicit_bzero(bufptr, ssh_buffer_get_len(privkey_buffer)); explicit_bzero(bufptr, ssh_buffer_get_len(privkey_buffer));
ssh_buffer_free(privkey_buffer); SSH_BUFFER_FREE(privkey_buffer);
} }
SAFE_FREE(pubkey_s); SAFE_FREE(pubkey_s);
SAFE_FREE(kdf_options); SAFE_FREE(kdf_options);
SAFE_FREE(salt); SAFE_FREE(salt);
if (buffer != NULL) { if (buffer != NULL) {
ssh_buffer_free(buffer); SSH_BUFFER_FREE(buffer);
} }
return str; return str;