mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 20:51:58 +00:00
FS-9652: improve sql sanitization
This commit is contained in:
@@ -1404,7 +1404,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
|
||||
if (presence_id || presence_data) {
|
||||
char *sql = switch_mprintf("update sip_dialogs set presence_id='%q',presence_data='%q' "
|
||||
"where uuid='%s';\n", switch_str_nil(presence_id), switch_str_nil(presence_data),
|
||||
"where uuid='%q';\n", switch_str_nil(presence_id), switch_str_nil(presence_data),
|
||||
switch_core_session_get_uuid(session));
|
||||
switch_assert(sql);
|
||||
sofia_glue_execute_sql_now(tech_pvt->profile, &sql, SWITCH_TRUE);
|
||||
@@ -3802,7 +3802,7 @@ static void select_from_profile(sofia_profile_t *profile,
|
||||
"from sip_registrations where profile_name='%q' "
|
||||
"and upper(sip_user)=upper('%q') "
|
||||
"and (sip_host='%q' or presence_hosts like '%%%q%%') "
|
||||
"and contact not like '%%%s%%'", (concat != NULL) ? concat : "", profile->name, user, domain, domain, exclude_contact);
|
||||
"and contact not like '%%%q%%'", (concat != NULL) ? concat : "", profile->name, user, domain, domain, exclude_contact);
|
||||
} else {
|
||||
sql = switch_mprintf("select contact, profile_name, '%q' "
|
||||
"from sip_registrations where profile_name='%q' "
|
||||
@@ -5282,12 +5282,12 @@ void general_event_handler(switch_event_t *event)
|
||||
} else {
|
||||
if (!strcasecmp(es, "message-summary")) {
|
||||
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
|
||||
"from sip_registrations where mwi_user='%s' and mwi_host='%q'",
|
||||
"from sip_registrations where mwi_user='%q' and mwi_host='%q'",
|
||||
ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
|
||||
);
|
||||
} else {
|
||||
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
|
||||
"from sip_registrations where sip_user='%s' and sip_host='%q'",
|
||||
"from sip_registrations where sip_user='%q' and sip_host='%q'",
|
||||
ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
|
||||
);
|
||||
|
||||
@@ -5389,7 +5389,7 @@ void general_event_handler(switch_event_t *event)
|
||||
"from sip_subscriptions where event='as-feature-event' and call_id='%q'", stream.data, ct, call_id);
|
||||
} else {
|
||||
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,call_id,full_from,full_to,expires,'%q', '%q' "
|
||||
"from sip_subscriptions where event='as-feature-event' and sip_user='%s' and sip_host='%q'", stream.data, ct, switch_str_nil(user), switch_str_nil(host)
|
||||
"from sip_subscriptions where event='as-feature-event' and sip_user='%q' and sip_host='%q'", stream.data, ct, switch_str_nil(user), switch_str_nil(host)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2782,10 +2782,10 @@ void event_handler(switch_event_t *event)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
|
||||
} else {
|
||||
if (!strcmp(ping_status, "REACHABLE")) {
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='%s' where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='%q' where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
"Reachable", from_user, from_host, call_id);
|
||||
} else {
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='%s' where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='%q' where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
"Unreachable", from_user, from_host, call_id);
|
||||
}
|
||||
if (sql) {
|
||||
@@ -6182,7 +6182,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||
sip_user_status.status_len = sizeof(ping_status);
|
||||
sip_user_status.contact = sip_contact;
|
||||
sip_user_status.contact_len = sizeof(sip_contact);
|
||||
sql = switch_mprintf("select ping_status, ping_count, contact from sip_registrations where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("select ping_status, ping_count, contact from sip_registrations where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, call_id);
|
||||
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_sip_user_status_callback, &sip_user_status);
|
||||
switch_safe_free(sql);
|
||||
@@ -6192,7 +6192,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||
if (sip_user_status.count >= 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Ping to sip user '%s@%s' failed with code %d - count %d, state %s\n",
|
||||
sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, status, sip_user_status.count, sip_user_status.status);
|
||||
sql = switch_mprintf("update sip_registrations set ping_count=%d, ping_time=%d where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("update sip_registrations set ping_count=%d, ping_time=%d where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
sip_user_status.count, ping_time, sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, call_id);
|
||||
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
||||
switch_safe_free(sql);
|
||||
@@ -6201,7 +6201,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||
if (strcmp(sip_user_status.status, "Unreachable")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Sip user '%s@%s' is now Unreachable\n",
|
||||
sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='Unreachable', ping_time=%d where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='Unreachable', ping_time=%d where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
ping_time, sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, call_id);
|
||||
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
||||
switch_safe_free(sql);
|
||||
@@ -6213,7 +6213,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Expire sip user '%s@%s' due to options failure\n",
|
||||
sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
|
||||
|
||||
sql = switch_mprintf("update sip_registrations set expires=%ld, ping_time=%d where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("update sip_registrations set expires=%ld, ping_time=%d where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
(long) now, ping_time, sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, call_id);
|
||||
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
||||
switch_safe_free(sql);
|
||||
@@ -6225,7 +6225,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||
if (sip_user_status.count <= sip_user_ping_max) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Ping to sip user '%s@%s' succeeded with code %d - count %d, state %s\n",
|
||||
sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, status, sip_user_status.count, sip_user_status.status);
|
||||
sql = switch_mprintf("update sip_registrations set ping_count=%d, ping_time=%d where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("update sip_registrations set ping_count=%d, ping_time=%d where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
sip_user_status.count, ping_time, sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, call_id);
|
||||
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
||||
switch_safe_free(sql);
|
||||
@@ -6234,7 +6234,7 @@ static void sofia_handle_sip_r_options(switch_core_session_t *session, int statu
|
||||
if (strcmp(sip_user_status.status, "Reachable")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Sip user '%s@%s' is now Reachable\n",
|
||||
sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='Reachable' where sip_user='%s' and sip_host='%s' and call_id='%q'",
|
||||
sql = switch_mprintf("update sip_registrations set ping_status='Reachable' where sip_user='%q' and sip_host='%q' and call_id='%q'",
|
||||
sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, call_id);
|
||||
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
||||
switch_safe_free(sql);
|
||||
@@ -6829,7 +6829,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
|
||||
const char *presence_id = switch_channel_get_variable(channel, "presence_id");
|
||||
|
||||
sql = switch_mprintf("update sip_dialogs set state='%q',presence_id='%q',presence_data='%q' "
|
||||
"where uuid='%s';\n", astate, switch_str_nil(presence_id), switch_str_nil(presence_data),
|
||||
"where uuid='%q';\n", astate, switch_str_nil(presence_id), switch_str_nil(presence_data),
|
||||
switch_core_session_get_uuid(session));
|
||||
switch_assert(sql);
|
||||
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
|
||||
|
||||
@@ -527,7 +527,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
|
||||
char buf[512] = "";
|
||||
switch_console_callback_match_t *matches;
|
||||
|
||||
sql = switch_mprintf("select profile_name from sip_registrations where hostname='%q' and (sip_host='%s' or mwi_host='%s')",
|
||||
sql = switch_mprintf("select profile_name from sip_registrations where hostname='%q' and (sip_host='%q' or mwi_host='%q')",
|
||||
mod_sofia_globals.hostname, host, host);
|
||||
|
||||
if (list_profiles_full(NULL, NULL, &matches, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
||||
@@ -3081,7 +3081,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
|
||||
|
||||
if (!zstr(astate) && !zstr(uuid) &&
|
||||
helper && helper->stream.data && strcmp(helper->last_uuid, uuid) && strcasecmp(astate, "terminated") && strchr(uuid, '-')) {
|
||||
helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where hostname='%q' and profile_name='%q' and uuid='%s';",
|
||||
helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%q' where hostname='%q' and profile_name='%q' and uuid='%q';",
|
||||
astate, mod_sofia_globals.hostname, profile->name, uuid);
|
||||
switch_copy_string(helper->last_uuid, uuid, sizeof(helper->last_uuid));
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
|
||||
|
||||
if (now) {
|
||||
sql = switch_mprintf("select call_id from sip_shared_appearance_dialogs where hostname='%q' "
|
||||
"and profile_name='%s' and expires <= %ld", mod_sofia_globals.hostname, profile->name, (long) now);
|
||||
"and profile_name='%q' and expires <= %ld", mod_sofia_globals.hostname, profile->name, (long) now);
|
||||
|
||||
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_sla_dialog_del_callback, profile);
|
||||
free(sql);
|
||||
@@ -888,8 +888,8 @@ void sofia_reg_check_ping_expire(sofia_profile_t *profile, time_t now, int inter
|
||||
if (sofia_test_pflag(profile, PFLAG_ALL_REG_OPTIONS_PING)) {
|
||||
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,"
|
||||
"expires,user_agent,server_user,server_host,profile_name "
|
||||
"from sip_registrations where hostname='%s' and "
|
||||
"profile_name='%s' and orig_hostname='%s' and "
|
||||
"from sip_registrations where hostname='%q' and "
|
||||
"profile_name='%q' and orig_hostname='%q' and "
|
||||
"ping_expires > 0 and ping_expires <= %ld",
|
||||
mod_sofia_globals.hostname, profile->name, mod_sofia_globals.hostname, (long) now);
|
||||
|
||||
@@ -899,7 +899,7 @@ void sofia_reg_check_ping_expire(sofia_profile_t *profile, time_t now, int inter
|
||||
sql = switch_mprintf(" select call_id,sip_user,sip_host,contact,status,rpid, "
|
||||
" expires,user_agent,server_user,server_host,profile_name "
|
||||
" from sip_registrations where (status like '%%UDP-NAT%%' or force_ping=1)"
|
||||
" and hostname='%s' and profile_name='%s' and ping_expires > 0 and ping_expires <= %ld ",
|
||||
" and hostname='%q' and profile_name='%q' and ping_expires > 0 and ping_expires <= %ld ",
|
||||
mod_sofia_globals.hostname, profile->name, (long) now);
|
||||
|
||||
sofia_glue_execute_sql_callback(profile, profile->dbh_mutex, sql, sofia_reg_nat_callback, profile);
|
||||
@@ -908,8 +908,8 @@ void sofia_reg_check_ping_expire(sofia_profile_t *profile, time_t now, int inter
|
||||
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,"
|
||||
"expires,user_agent,server_user,server_host,profile_name "
|
||||
"from sip_registrations where (status like '%%NAT%%' "
|
||||
"or contact like '%%fs_nat=yes%%' or force_ping=1) and hostname='%s' "
|
||||
"and profile_name='%s' and orig_hostname='%s' and "
|
||||
"or contact like '%%fs_nat=yes%%' or force_ping=1) and hostname='%q' "
|
||||
"and profile_name='%q' and orig_hostname='%q' and "
|
||||
"ping_expires > 0 and ping_expires <= %ld",
|
||||
mod_sofia_globals.hostname, profile->name, mod_sofia_globals.hostname, (long) now);
|
||||
|
||||
@@ -918,8 +918,8 @@ void sofia_reg_check_ping_expire(sofia_profile_t *profile, time_t now, int inter
|
||||
} else {
|
||||
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,"
|
||||
"expires,user_agent,server_user,server_host,profile_name "
|
||||
"from sip_registrations where force_ping=1 and hostname='%s' "
|
||||
"and profile_name='%s' and orig_hostname='%s' and "
|
||||
"from sip_registrations where force_ping=1 and hostname='%q' "
|
||||
"and profile_name='%q' and orig_hostname='%q' and "
|
||||
"ping_expires > 0 and ping_expires <= %ld",
|
||||
mod_sofia_globals.hostname, profile->name, mod_sofia_globals.hostname, (long) now);
|
||||
|
||||
@@ -3230,7 +3230,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
|
||||
if (nc && cnonce && qop) {
|
||||
ncl = strtoul(nc, 0, 16);
|
||||
|
||||
sql = switch_mprintf("update sip_authentication set expires='%ld',last_nc=%lu where nonce='%s'",
|
||||
sql = switch_mprintf("update sip_authentication set expires='%ld',last_nc=%lu where nonce='%q'",
|
||||
(long)switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : DEFAULT_NONCE_TTL) + exptime, ncl, nonce);
|
||||
|
||||
switch_assert(sql != NULL);
|
||||
|
||||
Reference in New Issue
Block a user