]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
sorcery: Prevent SEGV in sorcery_wizard_create when there's no create function
authorGeorge Joseph <george.joseph@fairview5.com>
Fri, 3 Oct 2014 15:53:59 +0000 (15:53 +0000)
committerGeorge Joseph <george.joseph@fairview5.com>
Fri, 3 Oct 2014 15:53:59 +0000 (15:53 +0000)
When you call ast_sorcery_create() you don't necessarily know which wizard is
going to be invoked.  If it happens to be a wizard like 'config' that doesn't
have a 'create' virtual function you get a segfault in the
sorcery_wizard_create callback.  This patch catches the null function pointer,
does an ast_assert, and logs an error.

Review: https://reviewboard.asterisk.org/r/4044/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@424447 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/sorcery.c

index 9488dee4b2693dfb198c60c528321b11225af25f..730a47bbbb2240355f752692c4fb61783dffb017 100644 (file)
@@ -1574,6 +1574,12 @@ static int sorcery_wizard_create(void *obj, void *arg, int flags)
        const struct ast_sorcery_object_wizard *object_wizard = obj;
        const struct sorcery_details *details = arg;
 
+       if (!object_wizard->wizard->create) {
+               ast_assert(0);
+               ast_log(LOG_ERROR, "Sorcery wizard '%s' doesn't contain a 'create' virtual function.\n",
+                       object_wizard->wizard->name);
+               return 0;
+       }
        return (!object_wizard->caching && !object_wizard->wizard->create(details->sorcery, object_wizard->data, details->obj)) ? CMP_MATCH | CMP_STOP : 0;
 }