mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
Fix data race in coap_resolve_address_info()
This commit is contained in:
1 parent
bd47692407
commit
b4de71ee24
4 files changed
+116
-55
No files matched your search
+66
-35
@@ -666,14 +666,14 @@ update_coap_addr_port(coap_uri_scheme_t scheme, coap_addr_info_t *info,
|
||||
#if defined(WITH_LWIP) && !(LWIP_DNS)
|
||||
|
||||
coap_addr_info_t *
|
||||
coap_resolve_address_info(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
coap_resolve_address_info_lkd(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
ip_addr_t addr_ip;
|
||||
coap_addr_info_t *info = NULL;
|
||||
coap_addr_info_t *info_prev = NULL;
|
||||
@@ -682,6 +682,8 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
|
||||
(void)ai_hints_flags;
|
||||
|
||||
coap_lock_check_locked();
|
||||
|
||||
if (address == NULL || address->length == 0) {
|
||||
memset(&addr_ip, 0, sizeof(addr_ip));
|
||||
} else {
|
||||
@@ -718,18 +720,22 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
#elif !defined(RIOT_VERSION) && !defined(WITH_CONTIKI)
|
||||
|
||||
coap_addr_info_t *
|
||||
coap_resolve_address_info(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
coap_resolve_address_info_lkd(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
|
||||
struct addrinfo *res, *ainfo;
|
||||
struct addrinfo hints;
|
||||
#if COAP_CONSTRAINED_STACK
|
||||
static char addrstr[256];
|
||||
#else /* ! COAP_CONSTRAINED_STACK */
|
||||
char addrstr[256];
|
||||
#endif /* ! COAP_CONSTRAINED_STACK */
|
||||
int error;
|
||||
coap_addr_info_t *info = NULL;
|
||||
coap_addr_info_t *info_prev = NULL;
|
||||
@@ -737,6 +743,8 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
coap_addr_info_t *info_tmp;
|
||||
coap_uri_scheme_t scheme;
|
||||
|
||||
coap_lock_check_locked();
|
||||
|
||||
#if COAP_AF_UNIX_SUPPORT
|
||||
if (address && coap_host_is_unix_domain(address)) {
|
||||
/* There can only be one unique filename entry for AF_UNIX */
|
||||
@@ -915,14 +923,14 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
#include "net/utils.h"
|
||||
|
||||
coap_addr_info_t *
|
||||
coap_resolve_address_info(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
coap_resolve_address_info_lkd(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
#if COAP_IPV6_SUPPORT
|
||||
ipv6_addr_t addr_ipv6;
|
||||
#endif /* COAP_IPV6_SUPPORT */
|
||||
@@ -937,6 +945,8 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
(void)ai_hints_flags;
|
||||
int family = AF_UNSPEC;
|
||||
|
||||
coap_lock_check_locked();
|
||||
|
||||
if (address == NULL || address->length == 0) {
|
||||
memset(&addr_ipv6, 0, sizeof(addr_ipv6));
|
||||
#if COAP_IPV6_SUPPORT
|
||||
@@ -1009,14 +1019,14 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
#include <os/net/ipv6/uiplib.h>
|
||||
|
||||
coap_addr_info_t *
|
||||
coap_resolve_address_info(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
coap_resolve_address_info_lkd(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
uip_ipaddr_t addr_ip;
|
||||
coap_addr_info_t *info = NULL;
|
||||
coap_addr_info_t *info_prev = NULL;
|
||||
@@ -1026,6 +1036,8 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
|
||||
(void)ai_hints_flags;
|
||||
|
||||
coap_lock_check_locked();
|
||||
|
||||
if (address == NULL || address->length == 0) {
|
||||
memset(&addr_ip, 0, sizeof(addr_ip));
|
||||
} else {
|
||||
@@ -1075,6 +1087,20 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
#error "OS type not supported"
|
||||
|
||||
coap_addr_info_t *
|
||||
coap_resolve_address_info_lkd(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
uint16_t ws_port,
|
||||
uint16_t ws_secure_port,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
COAP_API coap_addr_info_t *
|
||||
coap_resolve_address_info(const coap_str_const_t *address,
|
||||
uint16_t port,
|
||||
uint16_t secure_port,
|
||||
@@ -1083,10 +1109,15 @@ coap_resolve_address_info(const coap_str_const_t *address,
|
||||
int ai_hints_flags,
|
||||
int scheme_hint_bits,
|
||||
coap_resolve_type_t type) {
|
||||
return NULL;
|
||||
}
|
||||
coap_addr_info_t *info_list;
|
||||
|
||||
#endif
|
||||
coap_lock_lock(return NULL);
|
||||
info_list = coap_resolve_address_info_lkd(address, port, secure_port, ws_port,
|
||||
ws_secure_port, ai_hints_flags,
|
||||
scheme_hint_bits, type);
|
||||
coap_lock_unlock();
|
||||
return info_list;
|
||||
}
|
||||
|
||||
void
|
||||
coap_free_address_info(coap_addr_info_t *info) {
|
||||
|
||||
+12
-12
@@ -602,14 +602,14 @@ coap_proxy_get_ongoing_session(coap_session_t *session,
|
||||
coap_address_t *local_addr = NULL;
|
||||
|
||||
/* resolve destination address where data should be sent */
|
||||
info_list = coap_resolve_address_info(&server_use.uri.host,
|
||||
server_use.uri.port,
|
||||
server_use.uri.port,
|
||||
server_use.uri.port,
|
||||
server_use.uri.port,
|
||||
0,
|
||||
1 << server_use.uri.scheme,
|
||||
COAP_RESOLVE_TYPE_REMOTE);
|
||||
info_list = coap_resolve_address_info_lkd(&server_use.uri.host,
|
||||
server_use.uri.port,
|
||||
server_use.uri.port,
|
||||
server_use.uri.port,
|
||||
server_use.uri.port,
|
||||
0,
|
||||
1 << server_use.uri.scheme,
|
||||
COAP_RESOLVE_TYPE_REMOTE);
|
||||
|
||||
if (info_list == NULL) {
|
||||
response->code = COAP_RESPONSE_CODE(502);
|
||||
@@ -1644,10 +1644,10 @@ coap_new_client_session_proxy_lkd(coap_context_t *ctx,
|
||||
#endif /* !COAP_IPV6_SUPPORT && ! COAP_IPV4_SUPPORT */
|
||||
remote.length = strlen((const char *)remote.s);
|
||||
/* resolve internal remote address where proxy session is 'connecting' to */
|
||||
info_list = coap_resolve_address_info(&remote, 0, 0, 0, 0,
|
||||
0,
|
||||
1 << COAP_URI_SCHEME_COAP,
|
||||
COAP_RESOLVE_TYPE_REMOTE);
|
||||
info_list = coap_resolve_address_info_lkd(&remote, 0, 0, 0, 0,
|
||||
0,
|
||||
1 << COAP_URI_SCHEME_COAP,
|
||||
COAP_RESOLVE_TYPE_REMOTE);
|
||||
if (!info_list) {
|
||||
coap_log_warn("coap_new_client_session_proxy: Unable to resolve IP address\n");
|
||||
return NULL;
|
||||
|
||||
Reference in new issue
Block a user