[Asterisk-code-review] utils.c: NULL terminate ast_base64decode_string. (asterisk[16])

George Joseph asteriskteam at digium.com
Tue Oct 6 09:08:02 CDT 2020


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15036 )

Change subject: utils.c: NULL terminate ast_base64decode_string.
......................................................................

utils.c: NULL terminate ast_base64decode_string.

With the addition of STIR/SHAKEN, the function ast_base64decode_string
was added for convenience since there is a lot of converting done during
the STIR/SHAKEN process. This function returned the decoded string for
you, but did not NULL terminate it, causing some issues (specifically
with MALLOC_DEBUG). Now, the returned string is NULL terminated, and the
documentation has been updated to reflect this.

Change-Id: Icdd7d05b323b0c47ff6ed43492937a03641bdcf5
---
M include/asterisk/utils.h
M main/utils.c
2 files changed, 3 insertions(+), 2 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index f6280eb..0ee11ee 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -267,7 +267,7 @@
  * \brief Same as ast_base64decode, but does the math for you and returns
  * a decoded string
  *
- * \note The returned string will need to be freed later
+ * \note The returned string will need to be freed later and IS NULL terminated
  *
  * \param src The source buffer
  *
diff --git a/main/utils.c b/main/utils.c
index 0b6c6493..827ee2e 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -331,12 +331,13 @@
 	}
 
 	decoded_len = (encoded_len / 4 * 3) - padding;
-	decoded_string = ast_calloc(1, decoded_len);
+	decoded_string = ast_malloc(decoded_len + 1);
 	if (!decoded_string) {
 		return NULL;
 	}
 
 	ast_base64decode(decoded_string, src, decoded_len);
+	decoded_string[decoded_len] = '\0';
 
 	return (char *)decoded_string;
 }

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Icdd7d05b323b0c47ff6ed43492937a03641bdcf5
Gerrit-Change-Number: 15036
Gerrit-PatchSet: 2
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201006/8ce70e07/attachment.html>


More information about the asterisk-code-review mailing list