FS-9652: improve sql sanitization

This commit is contained in:
Mike Jerris committed 2016-11-11 11:27:35 -06:00
1 parent 53dbe5d84a
commit e1b3ee1efd
20 files changed
+148 -145

No files matched your search

@@ -366,9 +366,9 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
pq_var = switch_mprintf("null,", var);
} else {
if (cdr_field->quote) {
pq_var = switch_mprintf("'%s',", var);
pq_var = switch_mprintf("'%q',", var);
} else {
pq_var = switch_mprintf("%s,", var);
pq_var = switch_mprintf("%q,", var);
}
}
@@ -159,7 +159,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
return SWITCH_STATUS_FALSE;
}
sql = switch_mprintf("INSERT INTO %s VALUES (%s)", globals.db_table, expanded_vars);
sql = switch_mprintf("INSERT INTO %q VALUES (%s)", globals.db_table, expanded_vars);
assert(sql);
write_cdr(sql);
switch_safe_free(sql);
@@ -262,7 +262,7 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
dbh = cdr_get_db_handle();
if (dbh) {
select_sql = switch_mprintf("SELECT * FROM %s LIMIT 1", globals.db_table);
select_sql = switch_mprintf("SELECT * FROM %q LIMIT 1", globals.db_table);
assert(select_sql);
create_sql = switch_mprintf(default_create_sql, globals.db_table);
@@ -340,7 +340,7 @@ static switch_status_t odbc_cdr_reporting(switch_core_session_t *session)
}
switch_safe_free(i_hi);
sql = switch_mprintf("INSERT INTO %s (%s) VALUES (%s)", table_name, stream_field.data, stream_value.data);
sql = switch_mprintf("INSERT INTO %q (%s) VALUES (%s)", table_name, stream_field.data, stream_value.data);
if (globals.debug_sql == SWITCH_TRUE) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "sql %s\n", sql);
}
+2 -2
View File
@@ -139,7 +139,7 @@ int channelList_load(netsnmp_cache *cache, void *vmagic)
idx = 1;
sprintf(sql, "SELECT * FROM channels WHERE hostname='%s' ORDER BY created_epoch", switch_core_get_switchname());
switch_snprintfv(sql, sizeof(sql), "SELECT * FROM channels WHERE hostname='%q' ORDER BY created_epoch", switch_core_get_switchname());
switch_cache_db_execute_sql_callback(dbh, sql, channelList_callback, NULL, NULL);
switch_cache_db_release_db_handle(&dbh);
@@ -243,7 +243,7 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio
return SNMP_ERR_GENERR;
}
sprintf(sql, "SELECT COUNT(*) FROM calls WHERE hostname='%s'", switch_core_get_switchname());
switch_snprintfv(sql, sizeof(sql), "SELECT COUNT(*) FROM calls WHERE hostname='%q'", switch_core_get_switchname());
switch_cache_db_execute_sql_callback(dbh, sql, sql_count_callback, &int_val, NULL);
snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
switch_cache_db_release_db_handle(&dbh);