[Asterisk-code-review] res_crypto: Memory issues and uninitialized variable errors (asterisk[20])

Friendly Automation asteriskteam at digium.com
Mon Sep 19 10:05:40 CDT 2022


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/19270 )

Change subject: res_crypto: Memory issues and uninitialized variable errors
......................................................................

res_crypto: Memory issues and uninitialized variable errors

ASTERISK-30235

Change-Id: Ia1e326e7b52cd06fd5e6c9009e3e63193c92f6cd
---
M main/test.c
M tests/test_crypto.c
2 files changed, 21 insertions(+), 5 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit




diff --git a/main/test.c b/main/test.c
index 747262c..03de33b 100644
--- a/main/test.c
+++ b/main/test.c
@@ -316,9 +316,13 @@
 void ast_test_capture_free(struct ast_test_capture *capture)
 {
 	if (capture) {
-		free(capture->outbuf);
+		/*
+		 * Need to use ast_std_free because this memory wasn't
+		 * allocated by the astmm functions.
+		 */
+		ast_std_free(capture->outbuf);
 		capture->outbuf = NULL;
-		free(capture->errbuf);
+		ast_std_free(capture->errbuf);
 		capture->errbuf = NULL;
 	}
 	capture->pid = -1;
@@ -330,6 +334,7 @@
 	int fd0[2] = { -1, -1 }, fd1[2] = { -1, -1 }, fd2[2] = { -1, -1 };
 	pid_t pid = -1;
 	int status = 0;
+	FILE *cmd = NULL, *out = NULL, *err = NULL;
 
 	memset(capture, 0, sizeof(*capture));
 	capture->pid = capture->exitcode = -1;
@@ -379,8 +384,6 @@
 		exit(1);
 
 	} else {
-		FILE *cmd = NULL, *out = NULL, *err = NULL;
-
 		char buf[BUFSIZ];
 		int wstatus, n, nfds;
 		fd_set readfds, writefds;
diff --git a/tests/test_crypto.c b/tests/test_crypto.c
index 141781b..a3a0004 100644
--- a/tests/test_crypto.c
+++ b/tests/test_crypto.c
@@ -49,7 +49,7 @@
 
 static char *hexstring(const unsigned char *data, unsigned datalen)
 {
-	char *buf = alloca(datalen * 2 + 1);
+	char *buf = ast_malloc(datalen * 2 + 1);
 	unsigned n;
 
 	for (n = 0; n < datalen; ++n) {
@@ -532,6 +532,7 @@
 	res = AST_TEST_PASS;
 
 cleanup:
+	ast_free(args[KEY]);
 	ast_test_capture_free(&cap);
 	return res;
 }
@@ -610,6 +611,7 @@
 	res = AST_TEST_PASS;
 
 cleanup:
+	ast_free(args[KEY]);
 	ast_test_capture_free(&cap);
 	return res;
 }

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19270
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: Ia1e326e7b52cd06fd5e6c9009e3e63193c92f6cd
Gerrit-Change-Number: 19270
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-Reviewer: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220919/a54856f8/attachment.html>


More information about the asterisk-code-review mailing list