[asterisk-commits] sgriepentrog: branch 13 r433064 - in /branches/13: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 17 17:15:12 CDT 2015


Author: sgriepentrog
Date: Tue Mar 17 17:15:09 2015
New Revision: 433064

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433064
Log:
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/


Modified:
    branches/13/include/asterisk/config.h
    branches/13/main/asterisk.c
    branches/13/main/codec_builtin.c
    branches/13/main/config.c
    branches/13/main/endpoints.c
    branches/13/main/manager.c
    branches/13/main/utils.c
    branches/13/main/xmldoc.c

Modified: branches/13/include/asterisk/config.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/config.h?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/include/asterisk/config.h (original)
+++ branches/13/include/asterisk/config.h Tue Mar 17 17:15:09 2015
@@ -844,8 +844,11 @@
  *
  * \details
  * This function is used to apply a base (template) to an existing category
- */
-void ast_category_inherit(struct ast_category *existing, const struct ast_category *base);
+ *
+ * \retval 0 if succeeded
+ * \retval -1 if the memory allocation failed
+ */
+int ast_category_inherit(struct ast_category *existing, const struct ast_category *base);
 
 /*!
  * \brief Removes and destroys all variables in a category

Modified: branches/13/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/asterisk.c?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/main/asterisk.c (original)
+++ branches/13/main/asterisk.c Tue Mar 17 17:15:09 2015
@@ -4378,34 +4378,34 @@
 	ast_builtins_init();
 
 	if (ast_utils_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_utils_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_tps_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_tps_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_fd_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_fd_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_pbx_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_pbx_init\n%s", term_quit());
 		exit(1);
 	}
 
 #ifdef TEST_FRAMEWORK
 	if (ast_test_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_test_init\n%s", term_quit());
 		exit(1);
 	}
 #endif
 
 	if (ast_translate_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_translate_init\n%s", term_quit());
 		exit(1);
 	}
 
@@ -4413,27 +4413,27 @@
 	ast_uuid_init();
 
 	if (ast_sorcery_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_sorcery_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_codec_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_codec_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_format_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_format_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_format_cache_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_format_cache_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_codec_builtin_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_codec_builtin_init\n%s", term_quit());
 		exit(1);
 	}
 
@@ -4445,7 +4445,7 @@
 	aco_init();
 
 	if (ast_bucket_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_bucket_init\n%s", term_quit());
 		exit(1);
 	}
 
@@ -4487,26 +4487,26 @@
 	initstate((unsigned int) getpid() * 65536 + (unsigned int) time(NULL), randompool, sizeof(randompool));
 
 	if (init_logger()) {		/* Start logging subsystem */
-		printf("%s", term_quit());
+		printf("Failed: init_logger\n%s", term_quit());
 		exit(1);
 	}
 
 	threadstorage_init();
 
 	if (ast_rtp_engine_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_rtp_engine_init\n%s", term_quit());
 		exit(1);
 	}
 
 	ast_autoservice_init();
 
 	if (ast_timing_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_timing_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_ssl_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_ssl_init\n%s", term_quit());
 		exit(1);
 	}
 
@@ -4521,87 +4521,87 @@
 	}
 
 	if (astdb_init()) {
-		printf("%s", term_quit());
+		printf("Failed: astdb_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_msg_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_msg_init\n%s", term_quit());
 		exit(1);
 	}
 
 	/* initialize the data retrieval API */
 	if (ast_data_init()) {
-		printf ("%s", term_quit());
+		printf ("Failed: ast_data_init\n%s", term_quit());
 		exit(1);
 	}
 
 	ast_channels_init();
 
 	if (ast_endpoint_init()) {
-		printf ("%s", term_quit());
+		printf ("Failed: ast_endpoint_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_pickup_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_pickup_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_bridging_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_bridging_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_parking_stasis_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_parking_stasis_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_device_state_engine_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_device_state_engine_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_presence_state_engine_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_presence_state_engine_init\n%s", term_quit());
 		exit(1);
 	}
 
 	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);
 	}
 
 	if (ast_features_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_features_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (dnsmgr_init()) {		/* Initialize the DNS manager */
-		printf("%s", term_quit());
+		printf("Failed: dnsmgr_init\n%s", term_quit());
 		exit(1);
 	}
 
 	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);
 	}
 
 	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);
 	}
 
 	ast_http_init();		/* Start the HTTP server, if needed */
 
 	if (ast_indications_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_indications_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_cdr_engine_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_cdr_engine_init\n%s", term_quit());
 		exit(1);
 	}
 
@@ -4609,47 +4609,47 @@
 	ast_udptl_init();
 
 	if (ast_image_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_image_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_file_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_file_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (load_pbx()) {
-		printf("%s", term_quit());
+		printf("Failed: load_pbx\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_local_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_local_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_cel_engine_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_cel_engine_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (init_manager()) {
-		printf("%s", term_quit());
+		printf("Failed: init_manager\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_enum_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_enum_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_cc_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_cc_init\n%s", term_quit());
 		exit(1);
 	}
 
 	if (ast_sounds_index_init()) {
-		printf("%s", term_quit());
+		printf("Failed: ast_sounds_index_init\n%s", term_quit());
 		exit(1);
 	}
 

Modified: branches/13/main/codec_builtin.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/codec_builtin.c?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/main/codec_builtin.c (original)
+++ branches/13/main/codec_builtin.c Tue Mar 17 17:15:09 2015
@@ -776,7 +776,7 @@
 		struct ast_codec *__codec_ ## __LINE__; \
 		res |= __ast_codec_register(&(codec), NULL); \
 		__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__); \
 		ao2_ref(__fmt_ ## __LINE__, -1); \
 		ao2_ref(__codec_ ## __LINE__, -1); \

Modified: branches/13/main/config.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/config.c?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/main/config.c (original)
+++ branches/13/main/config.c Tue Mar 17 17:15:09 2015
@@ -1238,23 +1238,27 @@
 	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_category_template_instance *x;
 
 	x = ast_calloc(1, sizeof(*x));
 	if (!x) {
-		return;
+		return -1;
 	}
 	strcpy(x->name, base->name);
 	x->inst = base;
 	AST_LIST_INSERT_TAIL(&new->template_instances, x, next);
 	for (var = base->root; var; var = var->next) {
 		struct ast_variable *cloned = variable_clone(var);
+		if (!cloned) {
+			return -1;
+		}
 		cloned->inherited = 1;
 		ast_variable_append(new, cloned);
 	}
+	return 0;
 }
 
 struct ast_config *ast_config_new(void)
@@ -1691,7 +1695,10 @@
 						ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile);
 						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;
+					}
 				}
 			}
 		}

Modified: branches/13/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/endpoints.c?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/main/endpoints.c (original)
+++ branches/13/main/endpoints.c Tue Mar 17 17:15:09 2015
@@ -472,7 +472,8 @@
 		endpoint_snapshot_dtor,
 		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;
 	}
 

Modified: branches/13/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/manager.c?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/main/manager.c (original)
+++ branches/13/main/manager.c Tue Mar 17 17:15:09 2015
@@ -3620,7 +3620,10 @@
 			if (inherit) {
 				while ((tmpl_name = ast_strsep(&inherit, ',', AST_STRSEP_STRIP))) {
 					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 {
 						ast_category_destroy(category);
 						category = NULL;

Modified: branches/13/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/utils.c?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/main/utils.c (original)
+++ branches/13/main/utils.c Tue Mar 17 17:15:09 2015
@@ -611,7 +611,7 @@
 	return inet_ntop(AF_INET, &ia, buf, INET_ADDRSTRLEN);
 }
 
-static int dev_urandom_fd;
+static int dev_urandom_fd = -1;
 
 #ifndef __linux__
 #undef pthread_create /* For ast_pthread_create function only */

Modified: branches/13/main/xmldoc.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/xmldoc.c?view=diff&rev=433064&r1=433063&r2=433064
==============================================================================
--- branches/13/main/xmldoc.c (original)
+++ branches/13/main/xmldoc.c Tue Mar 17 17:15:09 2015
@@ -2214,6 +2214,9 @@
 		ast_xml_free_text(tmpstr);
 	} else {
 		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)) {
 			/* if found, parse children elements. */
 			if (xmldoc_parse_common_elements(tmp, "", "\n", &ret)) {
@@ -2263,7 +2266,7 @@
 	}
 
 	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));
 	}
 	ast_free(formatted);




More information about the asterisk-commits mailing list