]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_musiconhold: Don't crash when real-time doesn't return any entries
authorNathan Bruning <nathan@iperity.com>
Thu, 10 Dec 2020 23:06:56 +0000 (00:06 +0100)
committerSean Bright <sean.bright@gmail.com>
Tue, 15 Dec 2020 14:06:22 +0000 (08:06 -0600)
ASTERISK-29211 #close

Change-Id: Ifbf0a4f786ab2a52342f9d1a1db4c9907f069877

res/res_musiconhold.c

index db7dde71ad3c7c9a43ea16a1bd68c514aa0640d6..8ac3b927cf164db8142bd9f68faea858904c2294 100644 (file)
@@ -1613,18 +1613,21 @@ static struct ast_variable *load_realtime_musiconhold(const char *name)
                        char *category = NULL;
                        size_t entry_count = 0;
 
-                       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);
+                       /* 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);
+                                               }
                                        }
                                }
+                               ast_config_destroy(entries);
                        }
-                       ast_config_destroy(entries);
 
                        if (entry_count == 0) {
                                /* Behave as though this class doesn't exist */