Asterisk-16.12.0: func_odbc truncates field data to 15 symbols

OS: Gentoo
Asterisk: 16.12.0
DB: postgresql

Data row: number = 12345678 , name = ‘N234567890123456789012345678901234567890’
SQL: SELECT name FROM asterisk.phonebook WHERE number = '12345678' LIMIT 1;

Tests:
psql (PostgreSQL CLI): N234567890123456789012345678901234567890
icli (unixODBC CLI): N234567890123456789012345678901234567890
func_ODBC (Asterisk): N23456789012345

Investigation: after brief looking at func_odbc.c, it looks all field name and field data buffers sizes are hard-coded to 16 bytes (15 symbols + null termination byte)

Questions:

  1. Any reason, why such limitation exist? Just nobody cared?
  2. How safe it would be to increase those buffers sizes to 64 bytes (or even 256)?

This dirty patch solved my problem:

diff -ur asterisk-16.12.0_OLD/funcs/func_odbc.c asterisk-16.12.0_NEW/funcs/func_odbc.c
--- asterisk-16.12.0_OLD/funcs/func_odbc.c	2020-07-16 19:00:28.000000000 +0300
+++ asterisk-16.12.0_NEW/funcs/func_odbc.c	2020-09-11 22:52:46.337103514 +0300
@@ -100,6 +100,7 @@
 
 static char *config = "func_odbc.conf";
 
+#define RAY_TEST_CONST	64
 #define DEFAULT_SINGLE_DB_CONNECTION 0
 
 static int single_db_connection;
@@ -520,8 +521,8 @@
 	);
 	SQLHSTMT stmt = NULL;
 	SQLLEN rows=0;
-	struct ast_str *buf = ast_str_thread_get(&sql_buf, 16);
-	struct ast_str *insertbuf = ast_str_thread_get(&sql2_buf, 16);
+	struct ast_str *buf = ast_str_thread_get(&sql_buf, RAY_TEST_CONST);
+	struct ast_str *insertbuf = ast_str_thread_get(&sql2_buf, RAY_TEST_CONST);
 	const char *status = "FAILURE";
 	struct dsn *dsn = NULL;
 
@@ -715,7 +716,7 @@
 	struct odbc_obj *obj = NULL;
 	struct acf_odbc_query *query;
 	char varname[15], rowcount[12] = "-1";
-	struct ast_str *colnames = ast_str_thread_get(&colnames_buf, 16);
+	struct ast_str *colnames = ast_str_thread_get(&colnames_buf, RAY_TEST_CONST);
 	int res, x, y, buflen = 0, escapecommas, rowlimit = 1, multirow = 0, dsn_num, bogus_chan = 0;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(field)[100];
@@ -726,7 +727,7 @@
 	SQLSMALLINT collength;
 	struct odbc_datastore *resultset = NULL;
 	struct odbc_datastore_row *row = NULL;
-	struct ast_str *sql = ast_str_thread_get(&sql_buf, 16);
+	struct ast_str *sql = ast_str_thread_get(&sql_buf, RAY_TEST_CONST);
 	const char *status = "FAILURE";
 	struct dsn *dsn = NULL;
 
@@ -903,7 +904,7 @@
 		buf[0] = '\0';
 		for (x = 0; x < colcount; x++) {
 			int i;
-			struct ast_str *coldata = ast_str_thread_get(&coldata_buf, 16);
+			struct ast_str *coldata = ast_str_thread_get(&coldata_buf, RAY_TEST_CONST);
 			char *ptrcoldata;
 
 			if (!coldata) {
@@ -1448,7 +1449,7 @@
 		return CLI_SHOWUSAGE;
 	}
 
-	sql = ast_str_thread_get(&sql_buf, 16);
+	sql = ast_str_thread_get(&sql_buf, RAY_TEST_CONST);
 	if (!sql) {
 		return CLI_FAILURE;
 	}
@@ -1501,7 +1502,7 @@
 		int rows = 0, res, x;
 		SQLSMALLINT colcount = 0, collength;
 		SQLLEN indicator, octetlength;
-		struct ast_str *coldata = ast_str_thread_get(&coldata_buf, 16);
+		struct ast_str *coldata = ast_str_thread_get(&coldata_buf, RAY_TEST_CONST);
 		char colname[256];
 
 		if (!coldata) {
@@ -1664,7 +1665,7 @@
 		return CLI_SHOWUSAGE;
 	}
 
-	sql = ast_str_thread_get(&sql_buf, 16);
+	sql = ast_str_thread_get(&sql_buf, RAY_TEST_CONST);
 	if (!sql) {
 		return CLI_FAILURE;
 	}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.