diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-09-04 21:59:13 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-09-20 16:35:13 +0200 |
commit | e4711c469f1247c26e069d9d25f1669cb051bd27 (patch) | |
tree | ff486ab1b5d2e2f049ec63bb82b152226140de80 /src/pki.c | |
parent | 8410f43d8b7be357177fc58481446476d2748e9c (diff) | |
download | libssh-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>
Diffstat (limited to 'src/pki.c')
-rw-r--r-- | src/pki.c | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -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; } |