aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-09-04 21:59:13 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-09-20 16:35:13 +0200
commite4711c469f1247c26e069d9d25f1669cb051bd27 (patch)
treeff486ab1b5d2e2f049ec63bb82b152226140de80
parent8410f43d8b7be357177fc58481446476d2748e9c (diff)
downloadlibssh-e4711c469f1247c26e069d9d25f1669cb051bd27.tar.gz
libssh-e4711c469f1247c26e069d9d25f1669cb051bd27.tar.xz
libssh-e4711c469f1247c26e069d9d25f1669cb051bd27.zip
pki: Use strndup in ssh_pki_export_privkey_base64()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/pki.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/pki.c b/src/pki.c
index f463288a..d5c13048 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -620,8 +620,8 @@ int ssh_pki_export_privkey_base64(const ssh_key privkey,
void *auth_data,
char **b64_key)
{
- ssh_string blob;
- unsigned char *b64;
+ ssh_string blob = NULL;
+ char *b64 = NULL;
if (privkey == NULL || !ssh_key_is_private(privkey)) {
return SSH_ERROR;
@@ -642,18 +642,13 @@ int ssh_pki_export_privkey_base64(const ssh_key privkey,
return SSH_ERROR;
}
-
- b64 = malloc(ssh_string_len(blob));
- if(b64 == NULL){
- ssh_string_free(blob);
+ b64 = strndup(ssh_string_data(blob), ssh_string_len(blob));
+ ssh_string_free(blob);
+ if (b64 == NULL) {
return SSH_ERROR;
}
- memcpy(b64,ssh_string_data(blob),ssh_string_len(blob));
-
- ssh_string_free(blob);
-
- *b64_key = (char *)b64;
+ *b64_key = b64;
return SSH_OK;
}