Module: kamailio Branch: 5.3 Commit: 2ec8caa1ef9577fa4f21fb1fa2f9f6217a29f3eb URL: https://github.com/kamailio/kamailio/commit/2ec8caa1ef9577fa4f21fb1fa2f9f6217a29f3eb
Author: Daniel-Constantin Mierla <mico...@gmail.com> Committer: Daniel-Constantin Mierla <mico...@gmail.com> Date: 2019-10-07T16:29:16+02:00 http_async_client: use enough size to print pointer as string in build_hash_key() - use local string variables instead of allocation in pkg, because the values are needed only inside the function - use safer snprintf() instead of sprintf() - GH #2091 (cherry picked from commit 087654a5028cd800e17fcd9d1768135a60fd6706) --- Modified: src/modules/http_async_client/hm_hash.c --- Diff: https://github.com/kamailio/kamailio/commit/2ec8caa1ef9577fa4f21fb1fa2f9f6217a29f3eb.diff Patch: https://github.com/kamailio/kamailio/commit/2ec8caa1ef9577fa4f21fb1fa2f9f6217a29f3eb.patch --- diff --git a/src/modules/http_async_client/hm_hash.c b/src/modules/http_async_client/hm_hash.c index 9497809847..b18a8b9c37 100644 --- a/src/modules/http_async_client/hm_hash.c +++ b/src/modules/http_async_client/hm_hash.c @@ -62,39 +62,25 @@ int init_http_m_table(unsigned int size) unsigned int build_hash_key(void *p) { - str *hash_str; - char *pointer_str; - int len; + str hash_str; + char pointer_str[20]; unsigned int hash; - pointer_str = (char *)pkg_malloc(sizeof(p) + 1); - - if (pointer_str==0) { - LM_ERR("no more pkg mem\n"); + hash_str.len = snprintf(pointer_str, 20, "%p", p); + if(hash_str.len<=0 || hash_str.len>=20) { + LM_ERR("failed to print the pointer address\n"); return 0; } + LM_DBG("received id %p (%d)-> %s (%d)\n", p, (int)sizeof(p), pointer_str, + hash_str.len); - sprintf(pointer_str, "%p", p); - len = strlen(pointer_str); - LM_DBG("received id %p (%d)-> %s (%d)\n", p, (int)sizeof(p), pointer_str, len); + hash_str.s = pointer_str; - hash_str = (str *)pkg_malloc(sizeof(str)); - if (hash_str==0) { - LM_ERR("no more pkg mem\n"); - pkg_free(pointer_str); - return 0; - } - hash_str->s = pointer_str; - hash_str->len = len; - - hash = core_hash(hash_str, 0, hash_size); + hash = core_hash(&hash_str, 0, hash_size); LM_DBG("hash for %p is %d\n", p, hash); - pkg_free(pointer_str); - pkg_free(hash_str); - return hash; } _______________________________________________ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev