diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c index d1ca07d..988bc58 100644 --- a/funcs/func_odbc.c +++ b/funcs/func_odbc.c @@ -109,9 +109,11 @@ struct acf_odbc_query { AST_RWLIST_ENTRY(acf_odbc_query) list; char readhandle[5][30]; char writehandle[5][30]; - char sql_read[2048]; - char sql_write[2048]; - char sql_insert[2048]; + /* Using AST_REALTIME_DATA_MINLEN because these values can be read from + * from the static realtime var_val column. */ + char sql_read[AST_REALTIME_DATA_MINLEN]; + char sql_write[AST_REALTIME_DATA_MINLEN]; + char sql_insert[AST_REALTIME_DATA_MINLEN]; unsigned int flags; int rowlimit; struct ast_custom_function *acf; diff --git a/include/asterisk/config.h b/include/asterisk/config.h index 86c2bb5..33fb256 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -30,6 +30,22 @@ extern "C" { #include "asterisk/utils.h" #include "asterisk/inline_api.h" +/*! When using realtime database features, you can safely assume that your + * column data can be up to this many bytes in length (minus the trailing + * NUL) unless specified otherwise. + * + * Of course you are free to make your column smaller if you don't have any + * large data. If you make your column larger, Asterisk won't guarantee that + * the data won't be truncated. + * + * For example: + * - the static realtime var_val column, which can the value part of any + * configuration file; + * - the dynamic realtime sippeer setvar column, which is otherwise of + * unspecified length. + */ +#define AST_REALTIME_DATA_MINLEN 2048 + struct ast_config; struct ast_category; diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c index ef0d735..bd17f53 100644 --- a/res/res_config_odbc.c +++ b/res/res_config_odbc.c @@ -153,7 +153,7 @@ static struct ast_variable *realtime_odbc(const char *database, const char *tabl SQLHSTMT stmt; char sql[1024]; char coltitle[256]; - char rowdata[2048]; + char rowdata[AST_REALTIME_DATA_MINLEN]; char *op; const char *newparam; char *stringp; @@ -320,7 +320,7 @@ static struct ast_config *realtime_multi_odbc(const char *database, const char * SQLHSTMT stmt; char sql[1024]; char coltitle[256]; - char rowdata[2048]; + char rowdata[AST_REALTIME_DATA_MINLEN]; const char *initfield; char *op; const char *newparam; @@ -879,7 +879,7 @@ struct config_odbc_obj { unsigned long cat_metric; char category[128]; char var_name[128]; - char var_val[1024]; /* changed from 128 to 1024 via bug 8251 */ + char var_val[AST_REALTIME_DATA_MINLEN]; SQLLEN err; }; @@ -927,12 +927,10 @@ static struct ast_config *config_odbc(const char *database, const char *table, c SQLSMALLINT rowcount = 0; SQLHSTMT stmt; char last[128] = ""; - struct config_odbc_obj q; + struct config_odbc_obj q = { 0 }; struct ast_flags loader_flags = { 0 }; struct ast_flags connected_flag = { RES_ODBC_CONNECTED }; - memset(&q, 0, sizeof(q)); - if (!file || !strcmp (file, "res_config_odbc.conf")) return NULL; /* cant configure myself with myself ! */