Various: bugfixes found via chaos

Using DEBUG_CHAOS several instances of a null
pointer crash, and one uninitialized variable
were uncovered and fixed.  Also added details
on why Asterisk failed to initialize.

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

Merged revisions 433064 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@433065 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/42/42/1
Scott Griepentrog 10 years ago
parent f25b265329
commit 8c65c9167e

@ -844,8 +844,11 @@ void ast_category_append(struct ast_config *config, struct ast_category *cat);
* *
* \details * \details
* This function is used to apply a base (template) to an existing category * This function is used to apply a base (template) to an existing category
*
* \retval 0 if succeeded
* \retval -1 if the memory allocation failed
*/ */
void ast_category_inherit(struct ast_category *existing, const struct ast_category *base); int ast_category_inherit(struct ast_category *existing, const struct ast_category *base);
/*! /*!
* \brief Removes and destroys all variables in a category * \brief Removes and destroys all variables in a category

@ -4377,34 +4377,34 @@ int main(int argc, char *argv[])
ast_builtins_init(); ast_builtins_init();
if (ast_utils_init()) { if (ast_utils_init()) {
printf("%s", term_quit()); printf("Failed: ast_utils_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_tps_init()) { if (ast_tps_init()) {
printf("%s", term_quit()); printf("Failed: ast_tps_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_fd_init()) { if (ast_fd_init()) {
printf("%s", term_quit()); printf("Failed: ast_fd_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_pbx_init()) { if (ast_pbx_init()) {
printf("%s", term_quit()); printf("Failed: ast_pbx_init\n%s", term_quit());
exit(1); exit(1);
} }
#ifdef TEST_FRAMEWORK #ifdef TEST_FRAMEWORK
if (ast_test_init()) { if (ast_test_init()) {
printf("%s", term_quit()); printf("Failed: ast_test_init\n%s", term_quit());
exit(1); exit(1);
} }
#endif #endif
if (ast_translate_init()) { if (ast_translate_init()) {
printf("%s", term_quit()); printf("Failed: ast_translate_init\n%s", term_quit());
exit(1); exit(1);
} }
@ -4412,27 +4412,27 @@ int main(int argc, char *argv[])
ast_uuid_init(); ast_uuid_init();
if (ast_sorcery_init()) { if (ast_sorcery_init()) {
printf("%s", term_quit()); printf("Failed: ast_sorcery_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_codec_init()) { if (ast_codec_init()) {
printf("%s", term_quit()); printf("Failed: ast_codec_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_format_init()) { if (ast_format_init()) {
printf("%s", term_quit()); printf("Failed: ast_format_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_format_cache_init()) { if (ast_format_cache_init()) {
printf("%s", term_quit()); printf("Failed: ast_format_cache_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_codec_builtin_init()) { if (ast_codec_builtin_init()) {
printf("%s", term_quit()); printf("Failed: ast_codec_builtin_init\n%s", term_quit());
exit(1); exit(1);
} }
@ -4444,7 +4444,7 @@ int main(int argc, char *argv[])
aco_init(); aco_init();
if (ast_bucket_init()) { if (ast_bucket_init()) {
printf("%s", term_quit()); printf("Failed: ast_bucket_init\n%s", term_quit());
exit(1); exit(1);
} }
@ -4486,26 +4486,26 @@ int main(int argc, char *argv[])
initstate((unsigned int) getpid() * 65536 + (unsigned int) time(NULL), randompool, sizeof(randompool)); initstate((unsigned int) getpid() * 65536 + (unsigned int) time(NULL), randompool, sizeof(randompool));
if (init_logger()) { /* Start logging subsystem */ if (init_logger()) { /* Start logging subsystem */
printf("%s", term_quit()); printf("Failed: init_logger\n%s", term_quit());
exit(1); exit(1);
} }
threadstorage_init(); threadstorage_init();
if (ast_rtp_engine_init()) { if (ast_rtp_engine_init()) {
printf("%s", term_quit()); printf("Failed: ast_rtp_engine_init\n%s", term_quit());
exit(1); exit(1);
} }
ast_autoservice_init(); ast_autoservice_init();
if (ast_timing_init()) { if (ast_timing_init()) {
printf("%s", term_quit()); printf("Failed: ast_timing_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_ssl_init()) { if (ast_ssl_init()) {
printf("%s", term_quit()); printf("Failed: ast_ssl_init\n%s", term_quit());
exit(1); exit(1);
} }
@ -4520,87 +4520,87 @@ int main(int argc, char *argv[])
} }
if (astdb_init()) { if (astdb_init()) {
printf("%s", term_quit()); printf("Failed: astdb_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_msg_init()) { if (ast_msg_init()) {
printf("%s", term_quit()); printf("Failed: ast_msg_init\n%s", term_quit());
exit(1); exit(1);
} }
/* initialize the data retrieval API */ /* initialize the data retrieval API */
if (ast_data_init()) { if (ast_data_init()) {
printf ("%s", term_quit()); printf ("Failed: ast_data_init\n%s", term_quit());
exit(1); exit(1);
} }
ast_channels_init(); ast_channels_init();
if (ast_endpoint_init()) { if (ast_endpoint_init()) {
printf ("%s", term_quit()); printf ("Failed: ast_endpoint_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_pickup_init()) { if (ast_pickup_init()) {
printf("%s", term_quit()); printf("Failed: ast_pickup_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_bridging_init()) { if (ast_bridging_init()) {
printf("%s", term_quit()); printf("Failed: ast_bridging_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_parking_stasis_init()) { if (ast_parking_stasis_init()) {
printf("%s", term_quit()); printf("Failed: ast_parking_stasis_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_device_state_engine_init()) { if (ast_device_state_engine_init()) {
printf("%s", term_quit()); printf("Failed: ast_device_state_engine_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_presence_state_engine_init()) { if (ast_presence_state_engine_init()) {
printf("%s", term_quit()); printf("Failed: ast_presence_state_engine_init\n%s", term_quit());
exit(1); exit(1);
} }
if ((moduleresult = load_modules(1))) { /* Load modules, pre-load only */ if ((moduleresult = load_modules(1))) { /* Load modules, pre-load only */
printf("%s", term_quit()); printf("Failed: load_modules\n%s", term_quit());
exit(moduleresult == -2 ? 2 : 1); exit(moduleresult == -2 ? 2 : 1);
} }
if (ast_features_init()) { if (ast_features_init()) {
printf("%s", term_quit()); printf("Failed: ast_features_init\n%s", term_quit());
exit(1); exit(1);
} }
if (dnsmgr_init()) { /* Initialize the DNS manager */ if (dnsmgr_init()) { /* Initialize the DNS manager */
printf("%s", term_quit()); printf("Failed: dnsmgr_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_security_stasis_init()) { /* Initialize Security Stasis Topic and Events */ if (ast_security_stasis_init()) { /* Initialize Security Stasis Topic and Events */
printf("%s", term_quit()); printf("Failed: ast_security_stasis_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_named_acl_init()) { /* Initialize the Named ACL system */ if (ast_named_acl_init()) { /* Initialize the Named ACL system */
printf("%s", term_quit()); printf("Failed: ast_named_acl_init\n%s", term_quit());
exit(1); exit(1);
} }
ast_http_init(); /* Start the HTTP server, if needed */ ast_http_init(); /* Start the HTTP server, if needed */
if (ast_indications_init()) { if (ast_indications_init()) {
printf("%s", term_quit()); printf("Failed: ast_indications_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_cdr_engine_init()) { if (ast_cdr_engine_init()) {
printf("%s", term_quit()); printf("Failed: ast_cdr_engine_init\n%s", term_quit());
exit(1); exit(1);
} }
@ -4608,47 +4608,47 @@ int main(int argc, char *argv[])
ast_udptl_init(); ast_udptl_init();
if (ast_image_init()) { if (ast_image_init()) {
printf("%s", term_quit()); printf("Failed: ast_image_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_file_init()) { if (ast_file_init()) {
printf("%s", term_quit()); printf("Failed: ast_file_init\n%s", term_quit());
exit(1); exit(1);
} }
if (load_pbx()) { if (load_pbx()) {
printf("%s", term_quit()); printf("Failed: load_pbx\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_local_init()) { if (ast_local_init()) {
printf("%s", term_quit()); printf("Failed: ast_local_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_cel_engine_init()) { if (ast_cel_engine_init()) {
printf("%s", term_quit()); printf("Failed: ast_cel_engine_init\n%s", term_quit());
exit(1); exit(1);
} }
if (init_manager()) { if (init_manager()) {
printf("%s", term_quit()); printf("Failed: init_manager\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_enum_init()) { if (ast_enum_init()) {
printf("%s", term_quit()); printf("Failed: ast_enum_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_cc_init()) { if (ast_cc_init()) {
printf("%s", term_quit()); printf("Failed: ast_cc_init\n%s", term_quit());
exit(1); exit(1);
} }
if (ast_sounds_index_init()) { if (ast_sounds_index_init()) {
printf("%s", term_quit()); printf("Failed: ast_sounds_index_init\n%s", term_quit());
exit(1); exit(1);
} }

@ -776,7 +776,7 @@ static struct ast_codec t140 = {
struct ast_codec *__codec_ ## __LINE__; \ struct ast_codec *__codec_ ## __LINE__; \
res |= __ast_codec_register(&(codec), NULL); \ res |= __ast_codec_register(&(codec), NULL); \
__codec_ ## __LINE__ = ast_codec_get((codec).name, (codec).type, (codec).sample_rate); \ __codec_ ## __LINE__ = ast_codec_get((codec).name, (codec).type, (codec).sample_rate); \
__fmt_ ## __LINE__ = ast_format_create(__codec_ ## __LINE__); \ __fmt_ ## __LINE__ = __codec_ ## __LINE__ ? ast_format_create(__codec_ ## __LINE__) : NULL; \
res |= ast_format_cache_set(__fmt_ ## __LINE__); \ res |= ast_format_cache_set(__fmt_ ## __LINE__); \
ao2_ref(__fmt_ ## __LINE__, -1); \ ao2_ref(__fmt_ ## __LINE__, -1); \
ao2_ref(__codec_ ## __LINE__, -1); \ ao2_ref(__codec_ ## __LINE__, -1); \

@ -1238,23 +1238,27 @@ void ast_category_rename(struct ast_category *cat, const char *name)
ast_copy_string(cat->name, name, sizeof(cat->name)); ast_copy_string(cat->name, name, sizeof(cat->name));
} }
void ast_category_inherit(struct ast_category *new, const struct ast_category *base) int ast_category_inherit(struct ast_category *new, const struct ast_category *base)
{ {
struct ast_variable *var; struct ast_variable *var;
struct ast_category_template_instance *x; struct ast_category_template_instance *x;
x = ast_calloc(1, sizeof(*x)); x = ast_calloc(1, sizeof(*x));
if (!x) { if (!x) {
return; return -1;
} }
strcpy(x->name, base->name); strcpy(x->name, base->name);
x->inst = base; x->inst = base;
AST_LIST_INSERT_TAIL(&new->template_instances, x, next); AST_LIST_INSERT_TAIL(&new->template_instances, x, next);
for (var = base->root; var; var = var->next) { for (var = base->root; var; var = var->next) {
struct ast_variable *cloned = variable_clone(var); struct ast_variable *cloned = variable_clone(var);
if (!cloned) {
return -1;
}
cloned->inherited = 1; cloned->inherited = 1;
ast_variable_append(new, cloned); ast_variable_append(new, cloned);
} }
return 0;
} }
struct ast_config *ast_config_new(void) struct ast_config *ast_config_new(void)
@ -1691,7 +1695,10 @@ static int process_text_line(struct ast_config *cfg, struct ast_category **cat,
ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile); ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile);
return -1; return -1;
} }
ast_category_inherit(*cat, base); if (ast_category_inherit(*cat, base)) {
ast_log(LOG_ERROR, "Inheritence requested, but allocation failed\n");
return -1;
}
} }
} }
} }

@ -472,7 +472,8 @@ struct ast_endpoint_snapshot *ast_endpoint_snapshot_create(
endpoint_snapshot_dtor, endpoint_snapshot_dtor,
AO2_ALLOC_OPT_LOCK_NOLOCK); AO2_ALLOC_OPT_LOCK_NOLOCK);
if (ast_string_field_init(snapshot, 80) != 0) { if (!snapshot || ast_string_field_init(snapshot, 80) != 0) {
ao2_cleanup(snapshot);
return NULL; return NULL;
} }

@ -3628,7 +3628,10 @@ static enum error_type handle_updates(struct mansession *s, const struct message
if (inherit) { if (inherit) {
while ((tmpl_name = ast_strsep(&inherit, ',', AST_STRSEP_STRIP))) { while ((tmpl_name = ast_strsep(&inherit, ',', AST_STRSEP_STRIP))) {
if ((template = ast_category_get(cfg, tmpl_name, "TEMPLATES=restrict"))) { if ((template = ast_category_get(cfg, tmpl_name, "TEMPLATES=restrict"))) {
ast_category_inherit(category, template); if (ast_category_inherit(category, template)) {
result = FAILURE_ALLOCATION;
break;
}
} else { } else {
ast_category_destroy(category); ast_category_destroy(category);
category = NULL; category = NULL;

@ -611,7 +611,7 @@ const char *ast_inet_ntoa(struct in_addr ia)
return inet_ntop(AF_INET, &ia, buf, INET_ADDRSTRLEN); return inet_ntop(AF_INET, &ia, buf, INET_ADDRSTRLEN);
} }
static int dev_urandom_fd; static int dev_urandom_fd = -1;
#ifndef __linux__ #ifndef __linux__
#undef pthread_create /* For ast_pthread_create function only */ #undef pthread_create /* For ast_pthread_create function only */

@ -2214,6 +2214,9 @@ static struct ast_str *xmldoc_get_formatted(struct ast_xml_node *node, int raw_o
ast_xml_free_text(tmpstr); ast_xml_free_text(tmpstr);
} else { } else {
ret = ast_str_create(128); ret = ast_str_create(128);
if (!ret) {
return NULL;
}
for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) { for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
/* if found, parse children elements. */ /* if found, parse children elements. */
if (xmldoc_parse_common_elements(tmp, "", "\n", &ret)) { if (xmldoc_parse_common_elements(tmp, "", "\n", &ret)) {
@ -2263,7 +2266,7 @@ static char *_xmldoc_build_field(struct ast_xml_node *node, const char *var, int
} }
formatted = xmldoc_get_formatted(node, raw, raw); formatted = xmldoc_get_formatted(node, raw, raw);
if (ast_str_strlen(formatted) > 0) { if (formatted && ast_str_strlen(formatted) > 0) {
ret = ast_strdup(ast_str_buffer(formatted)); ret = ast_strdup(ast_str_buffer(formatted));
} }
ast_free(formatted); ast_free(formatted);

Loading…
Cancel
Save