[Asterisk-code-review] manager.c: Fix potential memory leak and corruption. (asterisk[15])

Jenkins2 asteriskteam at digium.com
Sat Feb 3 09:43:00 CST 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8130 )

Change subject: manager.c: Fix potential memory leak and corruption.
......................................................................

manager.c: Fix potential memory leak and corruption.

ast_str_append_event_header() could potentially leak and corrupt memory if
the ast_str needed to expand to add the AMI event header.

* Fixed to return error if the ast_str_append() failed.

Change-Id: I92f36b855540743b208d76e274152ee2d758176d
---
M main/manager.c
1 file changed, 5 insertions(+), 12 deletions(-)

Approvals:
  Corey Farrell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  Sean Bright: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/main/manager.c b/main/manager.c
index 576978c..a97f208 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -9490,23 +9490,16 @@
 }
 
 int ast_str_append_event_header(struct ast_str **fields_string,
-					const char *header, const char *value)
+	const char *header, const char *value)
 {
-	struct ast_str *working_str = *fields_string;
-
-	if (!working_str) {
-		working_str = ast_str_create(128);
-		if (!working_str) {
+	if (!*fields_string) {
+		*fields_string = ast_str_create(128);
+		if (!*fields_string) {
 			return -1;
 		}
-		*fields_string = working_str;
 	}
 
-	ast_str_append(&working_str, 0,
-		"%s: %s\r\n",
-		header, value);
-
-	return 0;
+	return (ast_str_append(fields_string, 0, "%s: %s\r\n", header, value) < 0) ? -1 : 0;
 }
 
 static void manager_event_blob_dtor(void *obj)

-- 
To view, visit https://gerrit.asterisk.org/8130
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I92f36b855540743b208d76e274152ee2d758176d
Gerrit-Change-Number: 8130
Gerrit-PatchSet: 2
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180203/d42545ac/attachment-0001.html>


More information about the asterisk-code-review mailing list