[Asterisk-code-review] res config sqlite3: Fix crashes when reading peers from sqli... (asterisk[master])

Christof Lauber asteriskteam at digium.com
Wed Feb 17 01:55:54 CST 2016


Christof Lauber has uploaded a new change for review.

  https://gerrit.asterisk.org/2263

Change subject: res_config_sqlite3: Fix crashes when reading peers from sqlite3 tables
......................................................................

res_config_sqlite3: Fix crashes when reading peers from sqlite3 tables

Introduced realloaction of ast_str buf in sqlite3_escape functions in case
the returned buffer from threadstorage was actually too small.

Change-Id: I3c5eb43aaade93ee457943daddc651781954c445
---
M res/res_config_sqlite3.c
1 file changed, 8 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/63/2263/1

diff --git a/res/res_config_sqlite3.c b/res/res_config_sqlite3.c
index 0b0a78c..5aea853 100644
--- a/res/res_config_sqlite3.c
+++ b/res/res_config_sqlite3.c
@@ -127,6 +127,10 @@
 	 * add two quotes, and convert NULL pointers to the word "NULL", but we
 	 * don't allow those anyway. Just going to use %q for now. */
 	struct ast_str *buf = ast_str_thread_get(ts, maxlen);
+	if (ast_str_size(buf) < maxlen) {
+		/* realloc if buf is too small */
+		ast_str_make_space(&buf, maxlen);
+	}
 	char *tmp = ast_str_buffer(buf);
 	char q = ts == &escape_value_buf ? '\'' : '"';
 
@@ -160,6 +164,10 @@
 {
 	size_t maxlen = strlen(param) * 2 + sizeof("\"\" =");
 	struct ast_str *buf = ast_str_thread_get(&escape_column_buf, maxlen);
+	if (ast_str_size(buf) < maxlen) {
+		/* realloc if buf is too small */
+		ast_str_make_space(&buf, maxlen);
+	}
 	char *tmp = ast_str_buffer(buf);
 	int space = 0;
 

-- 
To view, visit https://gerrit.asterisk.org/2263
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c5eb43aaade93ee457943daddc651781954c445
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Christof Lauber <christof.lauber at annax.ch>



More information about the asterisk-code-review mailing list