summaryrefslogtreecommitdiffstats
path: root/usr.bin/ssh/key.c
diff options
context:
space:
mode:
authormarkus <markus@openbsd.org>2002-07-04 10:41:47 +0000
committermarkus <markus@openbsd.org>2002-07-04 10:41:47 +0000
commit31568b606694a7b221771a21a2ac00dfc6dc5f51 (patch)
treeac30c91cdec3c440ebca95767e29673358f76ba6 /usr.bin/ssh/key.c
parentdocument port allocation (diff)
downloadwireguard-openbsd-31568b606694a7b221771a21a2ac00dfc6dc5f51.tar.xz
wireguard-openbsd-31568b606694a7b221771a21a2ac00dfc6dc5f51.zip
don't allocate, copy, and discard if there is not interested in the data; ok deraadt@
Diffstat (limited to 'usr.bin/ssh/key.c')
-rw-r--r--usr.bin/ssh/key.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/usr.bin/ssh/key.c b/usr.bin/ssh/key.c
index 34b36b0ebfe..0b03e991454 100644
--- a/usr.bin/ssh/key.c
+++ b/usr.bin/ssh/key.c
@@ -32,7 +32,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
-RCSID("$OpenBSD: key.c,v 1.47 2002/07/04 04:15:33 deraadt Exp $");
+RCSID("$OpenBSD: key.c,v 1.48 2002/07/04 10:41:47 markus Exp $");
#include <openssl/evp.h>
@@ -729,7 +729,6 @@ key_to_blob(Key *key, u_char **blobp, u_int *lenp)
{
Buffer b;
int len;
- u_char *buf;
if (key == NULL) {
error("key_to_blob: key == NULL");
@@ -755,16 +754,14 @@ key_to_blob(Key *key, u_char **blobp, u_int *lenp)
return 0;
}
len = buffer_len(&b);
- buf = xmalloc(len);
- memcpy(buf, buffer_ptr(&b), len);
- memset(buffer_ptr(&b), 0, len);
- buffer_free(&b);
if (lenp != NULL)
*lenp = len;
- if (blobp != NULL)
- *blobp = buf;
- else
- xfree(buf);
+ if (blobp != NULL) {
+ *blobp = xmalloc(len);
+ memcpy(*blobp, buffer_ptr(&b), len);
+ }
+ memset(buffer_ptr(&b), 0, len);
+ buffer_free(&b);
return len;
}