changeset 1912:8b4274d34fe8

Use buf_burn_free() instead of two calls
author Matt Johnston <matt@ucc.asn.au>
date Tue, 29 Mar 2022 23:47:30 +0800
parents ced53051e200
children 38c6fd7d7a82
files bignum.c buffer.c buffer.h common-kex.c common-runopts.c common-session.c dropbearkey.c gensignkey.c keyimport.c
diffstat 9 files changed, 18 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/bignum.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/bignum.c	Tue Mar 29 23:47:30 2022 +0800
@@ -100,5 +100,5 @@
 								plus header + some leeway*/
 	buf_putmpint(buf, mp);
 	hash_desc->process(hs, buf->data, buf->len);
-	buf_free(buf);
+	buf_burn_free(buf);
 }
--- a/buffer.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/buffer.c	Tue Mar 29 23:47:30 2022 +0800
@@ -55,11 +55,13 @@
 	m_free(buf);
 }
 
-/* overwrite the contents of the buffer to clear it */
-void buf_burn(const buffer* buf) {
+/* overwrite the contents of the buffer then free it */
+void buf_burn_free(buffer* buf) {
 	m_burn(buf->data, buf->size);
+	m_free(buf);
 }
 
+
 /* resize a buffer, pos and len will be repositioned if required when
  * downsizing */
 buffer* buf_resize(buffer *buf, unsigned int newsize) {
--- a/buffer.h	Tue Mar 29 23:27:55 2022 +0800
+++ b/buffer.h	Tue Mar 29 23:47:30 2022 +0800
@@ -44,7 +44,7 @@
 /* Possibly returns a new buffer*, like realloc() */
 buffer * buf_resize(buffer *buf, unsigned int newsize);
 void buf_free(buffer* buf);
-void buf_burn(const buffer* buf);
+void buf_burn_free(buffer* buf);
 buffer* buf_newcopy(const buffer* buf);
 void buf_setlen(buffer* buf, unsigned int len);
 void buf_incrlen(buffer* buf, unsigned int incr);
--- a/common-kex.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/common-kex.c	Tue Mar 29 23:47:30 2022 +0800
@@ -306,8 +306,7 @@
 	mp_clear(ses.dh_K);
 	m_free(ses.dh_K);
 	hash_desc->process(&hs, ses.hash->data, ses.hash->len);
-	buf_burn(ses.hash);
-	buf_free(ses.hash);
+	buf_burn_free(ses.hash);
 	ses.hash = NULL;
 
 	if (IS_DROPBEAR_CLIENT) {
@@ -803,8 +802,7 @@
 	}
 #endif
 
-	buf_burn(ses.kexhashbuf);
-	buf_free(ses.kexhashbuf);
+	buf_burn_free(ses.kexhashbuf);
 	m_burn(&hs, sizeof(hash_state));
 	ses.kexhashbuf = NULL;
 	
--- a/common-runopts.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/common-runopts.c	Tue Mar 29 23:47:30 2022 +0800
@@ -57,8 +57,7 @@
 	ret = DROPBEAR_SUCCESS;
 out:
 
-	buf_burn(buf);
-	buf_free(buf);
+	buf_burn_free(buf);
 	return ret;
 }
 
--- a/common-session.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/common-session.c	Tue Mar 29 23:47:30 2022 +0800
@@ -285,8 +285,7 @@
 	if (!*buf) {
 		return;
 	}
-	buf_burn(*buf);
-	buf_free(*buf);
+	buf_burn_free(*buf);
 	*buf = NULL;
 }
 
--- a/dropbearkey.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/dropbearkey.c	Tue Mar 29 23:47:30 2022 +0800
@@ -309,8 +309,7 @@
 	err = DROPBEAR_SUCCESS;
 
 out:
-	buf_burn(buf);
-	buf_free(buf);
+	buf_burn_free(buf);
 	buf = NULL;
 	if (key) {
 		sign_key_free(key);
--- a/gensignkey.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/gensignkey.c	Tue Mar 29 23:47:30 2022 +0800
@@ -181,8 +181,7 @@
 
 out:
 	if (buf) {
-		buf_burn(buf);
-		buf_free(buf);
+		buf_burn_free(buf);
 	}
 	
 	if (fn_temp) {
--- a/keyimport.c	Tue Mar 29 23:27:55 2022 +0800
+++ b/keyimport.c	Tue Mar 29 23:47:30 2022 +0800
@@ -504,16 +504,14 @@
 	}
 
 	if (buf) {
-		buf_burn(buf);
-		buf_free(buf);
+		buf_burn_free(buf);
 	}
 	m_burn(buffer, sizeof(buffer));
 	return ret;
 
 error:
 	if (buf) {
-		buf_burn(buf);
-		buf_free(buf);
+		buf_burn_free(buf);
 	}
 	m_burn(buffer, sizeof(buffer));
 	if (ret) {
@@ -898,8 +896,7 @@
 
 	error:
 	if (blobbuf) {
-		buf_burn(blobbuf);
-		buf_free(blobbuf);
+		buf_burn_free(blobbuf);
 	}
 	m_burn(key->keyblob, key->keyblob_size);
 	m_free(key->keyblob);
@@ -1070,8 +1067,7 @@
 		outblob = (unsigned char*)m_malloc(outlen);
 		memcpy(outblob, buf->data, buf->len);
 
-		buf_burn(buf);
-		buf_free(buf);
+		buf_burn_free(buf);
 		buf = NULL;
 
 		header = "-----BEGIN OPENSSH PRIVATE KEY-----\n";
@@ -1133,12 +1129,10 @@
 		m_free(outblob);
 	}
 	if (keyblob) {
-		buf_burn(keyblob);
-		buf_free(keyblob);
+		buf_burn_free(keyblob);
 	}
 	if (extrablob) {
-		buf_burn(extrablob);
-		buf_free(extrablob);
+		buf_burn_free(extrablob);
 	}
 	return ret;
 }