From: George Joseph Date: Fri, 3 Oct 2014 15:55:57 +0000 (+0000) Subject: sorcery: Prevent SEGV in sorcery_wizard_create when there's no create function X-Git-Tag: 14.0.0-beta1~1601 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4967478d180f2a512cfb6ff83fa115aac43978c6;p=thirdparty%2Fasterisk.git sorcery: Prevent SEGV in sorcery_wizard_create when there's no create function 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/ ........ Merged revisions 424447 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 424448 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@424449 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/sorcery.c b/main/sorcery.c index 85a699bcb8..9ddf77020b 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -1572,6 +1572,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; }