[asterisk-commits] mjordan: branch 1.8 r378375 - in /branches/1.8: funcs/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 2 15:49:01 CST 2013


Author: mjordan
Date: Wed Jan  2 15:48:57 2013
New Revision: 378375

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378375
Log:
Prevent crashes from occurring when reading from data sources with large values

When reading configuration data from an Asterisk .conf file or when pulling
data from an Asterisk RealTime backend, Asterisk was copying the data on the
stack for manipulation. Unfortunately, it is possible to read configuration
data or realtime data from some data source that provides a large blob of
characters. This could potentially cause a crash via a stack overflow.

This patch prevents large sets of data from being read from an ARA backend or
from an Asterisk conf file.

(issue ASTERISK-20658)
Reported by: wdoekes
Tested by: wdoekes, mmichelson
patches:
 * issueA20658_dont_process_overlong_config_lines.patch uploaded by wdoekes (license 5674)
 * issueA20658_func_realtime_limit.patch uploaded by wdoekes (license 5674)


Modified:
    branches/1.8/funcs/func_realtime.c
    branches/1.8/main/config.c

Modified: branches/1.8/funcs/func_realtime.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_realtime.c?view=diff&rev=378375&r1=378374&r2=378375
==============================================================================
--- branches/1.8/funcs/func_realtime.c (original)
+++ branches/1.8/funcs/func_realtime.c Wed Jan  2 15:48:57 2013
@@ -219,6 +219,13 @@
 	/* add space for delimiters and final '\0' */
 	resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1;
 
+	if (resultslen > len) {
+		ast_log(LOG_WARNING, "Failed to fetch. Realtime data is too large: need %zu, have %zu.\n", resultslen, len);
+		return -1;
+	}
+
+	/* len is going to be sensible, so we don't need to check for stack
+	 * overflows here. */
 	out = ast_str_alloca(resultslen);
 	for (var = head; var; var = var->next)
 		ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
@@ -439,6 +446,16 @@
 	/* add space for delimiters and final '\0' */
 	resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1;
 
+	if (resultslen > len) {
+		/* Unfortunately this does mean that we cannot destroy the row
+		 * anymore. But OTOH, we're not destroying someones data without
+		 * giving him the chance to look at it. */
+		ast_log(LOG_WARNING, "Failed to fetch/destroy. Realtime data is too large: need %zu, have %zu.\n", resultslen, len);
+		return -1;
+	}
+
+	/* len is going to be sensible, so we don't need to check for stack
+	 * overflows here. */
 	out = ast_str_alloca(resultslen);
 	for (var = head; var; var = var->next) {
 		ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);

Modified: branches/1.8/main/config.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/config.c?view=diff&rev=378375&r1=378374&r2=378375
==============================================================================
--- branches/1.8/main/config.c (original)
+++ branches/1.8/main/config.c Wed Jan  2 15:48:57 2013
@@ -1524,6 +1524,17 @@
 		while (!feof(f)) {
 			lineno++;
 			if (fgets(buf, sizeof(buf), f)) {
+				/* Skip lines that are too long */
+				if (strlen(buf) == sizeof(buf) - 1 && buf[sizeof(buf) - 1] != '\n') {
+					ast_log(LOG_WARNING, "Line %d too long, skipping. It begins with: %.32s...\n", lineno, buf);
+					while (fgets(buf, sizeof(buf), f)) {
+						if (strlen(buf) != sizeof(buf) - 1 || buf[sizeof(buf) - 1] == '\n') {
+							break;
+						}
+					}
+					continue;
+				}
+
 				if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && lline_buffer && ast_str_strlen(lline_buffer)) {
 					CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer));       /* add the current lline buffer to the comment buffer */
 					ast_str_reset(lline_buffer);        /* erase the lline buffer */




More information about the asterisk-commits mailing list