fix possible bad pointer in global vars (please test)

This commit is contained in:
Anthony Minessale
2011-02-02 15:43:26 -06:00
parent 89c5f3bf82
commit 4ae8282e6c
26 changed files with 185 additions and 100 deletions

View File

@@ -261,6 +261,11 @@ SWITCH_DECLARE(void) switch_core_dump_variables(switch_stream_handle_t *stream)
switch_mutex_unlock(runtime.global_mutex);
}
SWITCH_DECLARE(const char *) switch_core_get_hostname(void)
{
return runtime.hostname;
}
SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
{
char *val;
@@ -270,6 +275,32 @@ SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
return val;
}
SWITCH_DECLARE(char *) switch_core_get_variable_dup(const char *varname)
{
char *val = NULL, *v;
switch_mutex_lock(runtime.global_var_mutex);
if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
val = strdup(v);
}
switch_mutex_unlock(runtime.global_var_mutex);
return val;
}
SWITCH_DECLARE(char *) switch_core_get_variable_pdup(const char *varname, switch_memory_pool_t *pool)
{
char *val = NULL, *v;
switch_mutex_lock(runtime.global_var_mutex);
if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
val = switch_core_strdup(pool, v);
}
switch_mutex_unlock(runtime.global_var_mutex);
return val;
}
static void switch_core_unset_variables(void)
{
switch_mutex_lock(runtime.global_var_mutex);
@@ -1202,12 +1233,18 @@ static void switch_core_set_serial(void)
if ((fd = open(path, O_RDONLY, 0)) < 0) {
char *ip = switch_core_get_variable("local_ip_v4");
char *ip = switch_core_get_variable_dup("local_ip_v4");
uint32_t ipi = 0;
switch_byte_t *byte;
int i = 0;
switch_inet_pton(AF_INET, ip, &ipi);
if (ip) {
switch_inet_pton(AF_INET, ip, &ipi);
free(ip);
ip = NULL;
}
byte = (switch_byte_t *) & ipi;
for (i = 0; i < 8; i += 2) {
@@ -1237,7 +1274,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
char guess_ip[256];
int mask = 0;
struct in_addr in;
char hostname[256] = "";
if (runtime.runlevel > 0) {
/* one per customer */
@@ -1310,8 +1347,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
runtime.console = stdout;
}
gethostname(hostname, sizeof(hostname));
switch_core_set_variable("hostname", hostname);
gethostname(runtime.hostname, sizeof(runtime.hostname));
switch_core_set_variable("hostname", runtime.hostname);
switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
switch_core_set_variable("local_ip_v4", guess_ip);