git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@123009
65c4cc65-6c06-0410-ace0-
fbb531ad65f3
char *known_bad[] = {"select", "insert", "update", "delete", "drop", ";", "--", "\0"};
int idx;
char *known_bad[] = {"select", "insert", "update", "delete", "drop", ";", "--", "\0"};
int idx;
- if ((buf = ast_malloc(len + 1)) == NULL)
- {
+ if (!(buf = ast_calloc(1, len + 1))) {
ast_log(LOG_ERROR, "cdr_tds: Out of memory error\n");
return NULL;
}
ast_log(LOG_ERROR, "cdr_tds: Out of memory error\n");
return NULL;
}
buf_ptr = buf;
/* Escape single quotes */
buf_ptr = buf;
/* Escape single quotes */
- for (; *str && strlen(buf) < len; str++)
- {
- if (*str == '\'')
+ for (; *str && strlen(buf) < len; str++) {
+ if (*str == '\'') {
*buf_ptr++ = *str;
}
*buf_ptr = '\0';
/* Erase known bad input */
*buf_ptr++ = *str;
}
*buf_ptr = '\0';
/* Erase known bad input */
- for (idx=0; *known_bad[idx]; idx++)
- {
- while((srh_ptr = strcasestr(buf, known_bad[idx])))
- {
- memmove(srh_ptr, srh_ptr+strlen(known_bad[idx]), strlen(srh_ptr+strlen(known_bad[idx]))+1);
+ for (idx = 0; *known_bad[idx]; idx++) {
+ while ((srh_ptr = strcasestr(buf, known_bad[idx]))) {
+ memmove(srh_ptr, srh_ptr + strlen(known_bad[idx]), strlen(srh_ptr + strlen(known_bad[idx])) + 1);
char buf[80];
/* To make sure we have date variable if not insert null to SQL */
char buf[80];
/* To make sure we have date variable if not insert null to SQL */
- if (!ast_tvzero(tv))
- {
ast_localtime(&tv, &tm, NULL);
ast_strftime(buf, 80, DATE_FORMAT, &tm);
sprintf(dateField, "'%s'", buf);
ast_localtime(&tv, &tm, NULL);
ast_strftime(buf, 80, DATE_FORMAT, &tm);
sprintf(dateField, "'%s'", buf);
strcpy(dateField, "null");
}
}
strcpy(dateField, "null");
}
}
char query[128];
/* Connect to M$SQL Server */
char query[128];
/* Connect to M$SQL Server */
- if (!(login = tds_alloc_login()))
- {
+ if (!(login = tds_alloc_login())) {
ast_log(LOG_ERROR, "tds_alloc_login() failed.\n");
return -1;
}
ast_log(LOG_ERROR, "tds_alloc_login() failed.\n");
return -1;
}
tds_set_server(login, hostname);
tds_set_user(login, dbuser);
tds_set_passwd(login, password);
tds_set_server(login, hostname);
tds_set_user(login, dbuser);
tds_set_passwd(login, password);
tds_set_parent(tds, NULL);
connection = tds_read_config_info(tds, login, context->locale);
tds_set_parent(tds, NULL);
connection = tds_read_config_info(tds, login, context->locale);
ast_log(LOG_ERROR, "tds_read_config() failed.\n");
goto connect_fail;
}
ast_log(LOG_ERROR, "tds_read_config() failed.\n");
goto connect_fail;
}
- if (tds_connect(tds, connection) == TDS_FAIL)
- {
+ if (tds_connect(tds, connection) == TDS_FAIL) {
ast_log(LOG_ERROR, "Failed to connect to MSSQL server.\n");
tds = NULL; /* freed by tds_connect() on error */
#if (defined(FREETDS_0_63) || defined(FREETDS_0_64))
ast_log(LOG_ERROR, "Failed to connect to MSSQL server.\n");
tds = NULL; /* freed by tds_connect() on error */
#if (defined(FREETDS_0_63) || defined(FREETDS_0_64))
ast_config_destroy(cfg);
return 0;
}
ast_config_destroy(cfg);
return 0;
}
ptr = ast_variable_retrieve(cfg, "global", "hostname");
if (ptr) {
if (hostname)
ptr = ast_variable_retrieve(cfg, "global", "hostname");
if (ptr) {
if (hostname)