Commit 9535e7a2 authored by Cedric Roux's avatar Cedric Roux

bugfix: make some functions thread safe

Those functions modify a global char array (a string).

Let's pass a buffer to those functions, so that it's
thread safe. The caller has been modified, with hopefully
a buffer big enough (still bigger than what was there before,
so should not break more than it did).
parent 31c85b22
...@@ -357,6 +357,7 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ ...@@ -357,6 +357,7 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ
int rc; int rc;
int pid = RETURNerror; int pid = RETURNerror;
char apn_first_char[4]; char apn_first_char[4];
char str[128];
if (isprint(apn->value[0])) { if (isprint(apn->value[0])) {
apn_first_char[0] = '\0'; apn_first_char[0] = '\0';
...@@ -366,9 +367,9 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ ...@@ -366,9 +367,9 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ
LOG_TRACE(INFO, "ESM-PROC - PDN connectivity accepted by the network " LOG_TRACE(INFO, "ESM-PROC - PDN connectivity accepted by the network "
"(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1], "(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1],
(pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr) : (pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr, str) :
(pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr) : (pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr, str) :
esm_data_get_ipv4v6_addr(pdn_addr)); esm_data_get_ipv4v6_addr(pdn_addr, str));
/* Stop T3482 timer if running */ /* Stop T3482 timer if running */
esm_pt_stop_timer(esm_pt_data, pti); esm_pt_stop_timer(esm_pt_data, pti);
......
...@@ -204,13 +204,8 @@ typedef esm_data_context_t esm_data_t; ...@@ -204,13 +204,8 @@ typedef esm_data_context_t esm_data_t;
/****************** E X P O R T E D F U N C T I O N S ******************/ /****************** E X P O R T E D F U N C T I O N S ******************/
/****************************************************************************/ /****************************************************************************/
// FIXME prototype and buffer allocation char *esm_data_get_ipv4_addr(const OctetString *ip_addr, char *ret);
extern char ip_addr_str[100]; char *esm_data_get_ipv6_addr(const OctetString *ip_addr, char *ret);
char *esm_data_get_ipv4v6_addr(const OctetString *ip_addr, char *ret);
extern char *esm_data_get_ipv4_addr(const OctetString *ip_addr);
extern char *esm_data_get_ipv6_addr(const OctetString *ip_addr);
extern char *esm_data_get_ipv4v6_addr(const OctetString *ip_addr);
#endif /* __ESMDATA_H__*/ #endif /* __ESMDATA_H__*/
...@@ -22,47 +22,43 @@ ...@@ -22,47 +22,43 @@
#include "emmData.h" #include "emmData.h"
#include "esmData.h" #include "esmData.h"
// FIXME don't work for reentrant calls char *esm_data_get_ipv4_addr(const OctetString *ip_addr, char *ret)
char ip_addr_str[100];
// FIXME can't be extern and inline at same time !
inline char *esm_data_get_ipv4_addr(const OctetString *ip_addr)
{ {
if (ip_addr->length > 0) { if (ip_addr->length > 0) {
sprintf(ip_addr_str, "%u.%u.%u.%u", sprintf(ret, "%u.%u.%u.%u",
ip_addr->value[0], ip_addr->value[1], ip_addr->value[0], ip_addr->value[1],
ip_addr->value[2], ip_addr->value[3]); ip_addr->value[2], ip_addr->value[3]);
return ip_addr_str; return ret;
} }
return (NULL); return (NULL);
} }
inline char *esm_data_get_ipv6_addr(const OctetString *ip_addr) char *esm_data_get_ipv6_addr(const OctetString *ip_addr, char *ret)
{ {
if (ip_addr->length > 0) { if (ip_addr->length > 0) {
sprintf(ip_addr_str, "%x%.2x:%x%.2x:%x%.2x:%x%.2x", sprintf(ret, "%x%.2x:%x%.2x:%x%.2x:%x%.2x",
ip_addr->value[0], ip_addr->value[1], ip_addr->value[0], ip_addr->value[1],
ip_addr->value[2], ip_addr->value[3], ip_addr->value[2], ip_addr->value[3],
ip_addr->value[4], ip_addr->value[5], ip_addr->value[4], ip_addr->value[5],
ip_addr->value[6], ip_addr->value[7]); ip_addr->value[6], ip_addr->value[7]);
return ip_addr_str; return ret;
} }
return (NULL); return (NULL);
} }
inline char *esm_data_get_ipv4v6_addr(const OctetString *ip_addr) char *esm_data_get_ipv4v6_addr(const OctetString *ip_addr, char *ret)
{ {
if (ip_addr->length > 0) { if (ip_addr->length > 0) {
sprintf(ip_addr_str, "%u.%u.%u.%u / %x%.2x:%x%.2x:%x%.2x:%x%.2x", sprintf(ret, "%u.%u.%u.%u / %x%.2x:%x%.2x:%x%.2x:%x%.2x",
ip_addr->value[0], ip_addr->value[1], ip_addr->value[0], ip_addr->value[1],
ip_addr->value[2], ip_addr->value[3], ip_addr->value[2], ip_addr->value[3],
ip_addr->value[4], ip_addr->value[5], ip_addr->value[4], ip_addr->value[5],
ip_addr->value[6], ip_addr->value[7], ip_addr->value[6], ip_addr->value[7],
ip_addr->value[8], ip_addr->value[9], ip_addr->value[8], ip_addr->value[9],
ip_addr->value[10], ip_addr->value[11]); ip_addr->value[10], ip_addr->value[11]);
return ip_addr_str; return ret;
} }
return (NULL); return (NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment