[Asterisk-code-review] res_musiconhold: Don't crash when real-time doesn't return any entries (asterisk[18])

George Joseph asteriskteam at digium.com
Wed Dec 16 09:20:26 CST 2020


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

Change subject: res_musiconhold: Don't crash when real-time doesn't return any entries
......................................................................

res_musiconhold: Don't crash when real-time doesn't return any entries

ASTERISK-29211 #close

Change-Id: Ifbf0a4f786ab2a52342f9d1a1db4c9907f069877
---
M res/res_musiconhold.c
1 file changed, 11 insertions(+), 8 deletions(-)

Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index db7dde7..8ac3b92 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1613,18 +1613,21 @@
 			char *category = NULL;
 			size_t entry_count = 0;
 
-			while ((category = ast_category_browse(entries, category))) {
-				const char *entry = ast_variable_retrieve(entries, category, "entry");
+			/* entries is NULL if there are no results */
+			if (entries) {
+				while ((category = ast_category_browse(entries, category))) {
+					const char *entry = ast_variable_retrieve(entries, category, "entry");
 
-				if (entry) {
-					struct ast_variable *dup = ast_variable_new("entry", entry, "");
-					if (dup) {
-						entry_count++;
-						ast_variable_list_append(&var, dup);
+					if (entry) {
+						struct ast_variable *dup = ast_variable_new("entry", entry, "");
+						if (dup) {
+							entry_count++;
+							ast_variable_list_append(&var, dup);
+						}
 					}
 				}
+				ast_config_destroy(entries);
 			}
-			ast_config_destroy(entries);
 
 			if (entry_count == 0) {
 				/* Behave as though this class doesn't exist */

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

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Ifbf0a4f786ab2a52342f9d1a1db4c9907f069877
Gerrit-Change-Number: 15245
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Nathan Bruning <nathan at iperity.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201216/7178b3ac/attachment-0001.html>


More information about the asterisk-code-review mailing list