[sr-dev] git:5.5:459f40b5: http_client: clone name in http connection structures
Daniel-Constantin Mierla
miconda at gmail.com
Tue Jun 29 14:53:28 CEST 2021
Module: kamailio
Branch: 5.5
Commit: 459f40b52a8a6f8b2ef70a6986c686448ea572a8
URL: https://github.com/kamailio/kamailio/commit/459f40b52a8a6f8b2ef70a6986c686448ea572a8
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-06-29T14:41:50+02:00
http_client: clone name in http connection structures
- use name to lookup private memory structure, hash id is not unique,
can be collisions for different names
(cherry picked from commit 9429083c87b1323e31983cc71551676c199bf640)
---
Modified: src/modules/http_client/curlcon.c
Modified: src/modules/http_client/http_client.h
---
Diff: https://github.com/kamailio/kamailio/commit/459f40b52a8a6f8b2ef70a6986c686448ea572a8.diff
Patch: https://github.com/kamailio/kamailio/commit/459f40b52a8a6f8b2ef70a6986c686448ea572a8.patch
---
diff --git a/src/modules/http_client/curlcon.c b/src/modules/http_client/curlcon.c
index 7df146493f..b1bfa3bd48 100644
--- a/src/modules/http_client/curlcon.c
+++ b/src/modules/http_client/curlcon.c
@@ -172,7 +172,8 @@ curl_con_pkg_t *curl_get_pkg_connection(curl_con_t *con)
ccp = _curl_con_pkg_root;
while(ccp) {
- if(ccp->conid == con->conid) {
+ if(ccp->conid == con->conid && ccp->name.len == con->name.len
+ && strncmp(ccp->name.s, con->name.s, con->name.len) == 0) {
return ccp;
}
ccp = ccp->next;
@@ -814,8 +815,9 @@ curl_con_t *curl_init_con(str *name)
cc = cc->next;
}
- cc = (curl_con_t *)shm_malloc(sizeof(
- curl_con_t)); /* Connection structures are shared by all children processes */
+ /* Connection structures are shared by all children processes */
+ cc = (curl_con_t *)shm_malloc(sizeof(curl_con_t)
+ + (name->len + 1)*sizeof(char));
if(cc == NULL) {
LM_ERR("no shm memory\n");
return NULL;
@@ -823,7 +825,8 @@ curl_con_t *curl_init_con(str *name)
/* Each structure is allocated in package memory so each process can write into it without
any locks or such stuff */
- ccp = (curl_con_pkg_t *)pkg_malloc(sizeof(curl_con_pkg_t));
+ ccp = (curl_con_pkg_t *)pkg_malloc(sizeof(curl_con_pkg_t)
+ + (name->len + 1)*sizeof(char));
if(ccp == NULL) {
/* We failed to allocate ccp, so let's free cc and quit */
shm_free(cc);
@@ -831,17 +834,21 @@ curl_con_t *curl_init_con(str *name)
return NULL;
}
- memset(cc, 0, sizeof(curl_con_t));
+ memset(cc, 0, sizeof(curl_con_t) + (name->len + 1)*sizeof(char));
cc->next = _curl_con_root;
cc->conid = conid;
+ cc->name.s = (char*)cc + sizeof(curl_con_t);
+ memcpy(cc->name.s, name->s, name->len);
+ cc->name.len = name->len;
_curl_con_root = cc;
- cc->name = *name;
/* Put the new ccp first in line */
- memset(ccp, 0, sizeof(curl_con_pkg_t));
+ memset(ccp, 0, sizeof(curl_con_pkg_t) + (name->len + 1)*sizeof(char));
ccp->next = _curl_con_pkg_root;
ccp->conid = conid;
- ccp->curl = NULL;
+ ccp->name.s = (char*)ccp + sizeof(curl_con_pkg_t);
+ memcpy(ccp->name.s, name->s, name->len);
+ ccp->name.len = name->len;
_curl_con_pkg_root = ccp;
LM_DBG("CURL: Added connection [%.*s]\n", name->len, name->s);
diff --git a/src/modules/http_client/http_client.h b/src/modules/http_client/http_client.h
index 29b451ba4d..a37bdbe4a5 100644
--- a/src/modules/http_client/http_client.h
+++ b/src/modules/http_client/http_client.h
@@ -93,7 +93,7 @@ enum connection_status
typedef struct _curl_con
{
str name; /*!< Connection name */
- unsigned int conid; /*!< Connection ID */
+ unsigned int conid; /*!< Connection hash ID */
enum connection_status connstate; /*!< Connection status */
str url; /*!< The URL without schema (host + base URL)*/
str schema; /*!< The URL schema */
@@ -125,7 +125,8 @@ typedef struct _curl_con
/*! Per-process copy of connection object -stored in pkg memory */
typedef struct _curl_con_pkg
{
- unsigned int conid; /*!< Connection ID (referring to core connection id */
+ str name; /*!< Connection name */
+ unsigned int conid; /*!< Connection hash ID */
char redirecturl
[512]; /*!< Last redirect URL - to use for $curlredirect(curlcon) pv */
unsigned int last_result; /*!< Last result of accessing this connection */
More information about the sr-dev
mailing list