FS-8537: Passing nil to various lua functions causes segfault

Various functions exposed via lua do not check their parameters for null
causing freeswitch to segfault.

This change adds checking for null parameters and returns an error
instead of segfaulting.
This commit is contained in:
Mark Lipscombe
2015-11-15 10:40:20 +11:00
parent de7a123c8b
commit 4e9977507d
4 changed files with 63 additions and 18 deletions

View File

@@ -393,11 +393,13 @@ SWITCH_DECLARE(char *) switch_core_get_variable_dup(const char *varname)
{
char *val = NULL, *v;
switch_thread_rwlock_rdlock(runtime.global_var_rwlock);
if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
val = strdup(v);
if (varname) {
switch_thread_rwlock_rdlock(runtime.global_var_rwlock);
if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
val = strdup(v);
}
switch_thread_rwlock_unlock(runtime.global_var_rwlock);
}
switch_thread_rwlock_unlock(runtime.global_var_rwlock);
return val;
}
@@ -406,11 +408,13 @@ SWITCH_DECLARE(char *) switch_core_get_variable_pdup(const char *varname, switch
{
char *val = NULL, *v;
switch_thread_rwlock_rdlock(runtime.global_var_rwlock);
if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
val = switch_core_strdup(pool, v);
if (varname) {
switch_thread_rwlock_rdlock(runtime.global_var_rwlock);
if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
val = switch_core_strdup(pool, v);
}
switch_thread_rwlock_unlock(runtime.global_var_rwlock);
}
switch_thread_rwlock_unlock(runtime.global_var_rwlock);
return val;
}