prevent sql injection by using sqlite formatter on various code that generates sql stmts with switch_snprintf

This commit is contained in:
Anthony Minessale committed 2011-09-29 08:28:12 -05:00
1 parent cbfe83cc8f
commit 256a6264d4
4 files changed
+37 -37

No files matched your search

@@ -4078,11 +4078,11 @@ SWITCH_STANDARD_API(show_function)
holder.print_title = 0;
if ((cmdname = strchr(command, ' ')) && strcasecmp(cmdname, "as")) {
*cmdname++ = '\0';
switch_snprintf(sql, sizeof(sql) - 1,
"select name, syntax, description, ikey from interfaces where hostname='%s' and type = 'api' and name = '%s' order by name",
switch_snprintfv(sql, sizeof(sql),
"select name, syntax, description, ikey from interfaces where hostname='%s' and type = 'api' and name = '%q' order by name",
hostname, cmdname);
} else {
switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description, ikey from interfaces where hostname='%s' and type = 'api' order by name", hostname);
switch_snprintfv(sql, sizeof(sql), "select name, syntax, description, ikey from interfaces where hostname='%q' and type = 'api' order by name", hostname);
}
} else if (!strcasecmp(command, "nat_map")) {
switch_snprintf(sql, sizeof(sql) - 1,
@@ -2016,10 +2016,10 @@ static void voicemail_check_main(switch_core_session_t *session, vm_profile_t *p
"username='%s' and domain='%s' and flags='save'",
(long) switch_epoch_time_now(NULL), myid, domain_name);
vm_execute_sql(profile, sql, profile->mutex);
switch_snprintf(sql, sizeof(sql), "select file_path from voicemail_msgs where username='%s' and domain='%s' and flags='delete'", myid,
switch_snprintfv(sql, sizeof(sql), "select file_path from voicemail_msgs where username='%q' and domain='%q' and flags='delete'", myid,
domain_name);
vm_execute_sql_callback(profile, profile->mutex, sql, unlink_callback, NULL);
switch_snprintf(sql, sizeof(sql), "delete from voicemail_msgs where username='%s' and domain='%s' and flags='delete'", myid, domain_name);
switch_snprintfv(sql, sizeof(sql), "delete from voicemail_msgs where username='%q' and domain='%q' and flags='delete'", myid, domain_name);
vm_execute_sql(profile, sql, profile->mutex);
vm_check_state = VM_CHECK_FOLDER_SUMMARY;
@@ -2305,7 +2305,7 @@ static void voicemail_check_main(switch_core_session_t *session, vm_profile_t *p
}
thepass = thehash = NULL;
switch_snprintf(sql, sizeof(sql), "select * from voicemail_prefs where username='%s' and domain='%s'", myid, domain_name);
switch_snprintfv(sql, sizeof(sql), "select * from voicemail_prefs where username='%q' and domain='%q'", myid, domain_name);
vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
x_params = switch_xml_child(x_user, "variables");
@@ -3225,7 +3225,7 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, vm_p
goto end;
}
switch_snprintf(sql, sizeof(sql), "select * from voicemail_prefs where username='%s' and domain='%s'", id, domain_name);
switch_snprintfv(sql, sizeof(sql), "select * from voicemail_prefs where username='%q' and domain='%q'", id, domain_name);
vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
if (!vm_ext) {
@@ -3327,7 +3327,7 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, vm_p
callback.buf = disk_usage;
callback.len = sizeof(disk_usage);
switch_snprintf(sqlstmt, sizeof(sqlstmt), "select sum(message_len) from voicemail_msgs where username='%s' and domain='%s'", id, domain_name);
switch_snprintfv(sqlstmt, sizeof(sqlstmt), "select sum(message_len) from voicemail_msgs where username='%q' and domain='%q'", id, domain_name);
vm_execute_sql_callback(profile, profile->mutex, sqlstmt, sql2str_callback, &callback);
if (atoi(disk_usage) >= disk_quota) {
@@ -3633,7 +3633,7 @@ SWITCH_STANDARD_API(prefs_api_function)
}
switch_snprintf(sql, sizeof(sql), "select * from voicemail_prefs where username='%s' and domain='%s'", id, domain);
switch_snprintfv(sql, sizeof(sql), "select * from voicemail_prefs where username='%q' and domain='%q'", id, domain);
vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
if (!strcasecmp(how, "greeting_path")) {