aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-04-12 21:48:07 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-04-12 21:48:11 +0700
commit4f619c202c67dd68b1c3a13d40ad50fa2a6e582d (patch)
treefb2bced9a093aa8bbab94aeebc1e1e7de4bfbd37 /src/utils.c
parentb480b74192a7c00c4ea077286b921b96e42efabc (diff)
Fix incorrect buffer size calculation
Calling sizeof() on a pointer to dynamically allocated memory would result in getting size of the pointer (usually 4 or 8 bytes) itself, but not the size of allocated memory. Change-Id: I8ffda4dea2b7f9b4b76dfeecad1fab6384c5a62c Fixes: CID#197629, CID#197628, CID#197627 Fixes: CID#197626, CID#197625, CID#197624
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/utils.c b/src/utils.c
index 896e9177..b66721e6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -351,10 +351,11 @@ char *osmo_hexdump(const unsigned char *buf, int len)
*/
char *osmo_hexdump_c(const void *ctx, const unsigned char *buf, int len)
{
- char *hexd_buff = talloc_size(ctx, len*3 + 1);
+ size_t hexd_buff_len = len * 3 + 1;
+ char *hexd_buff = talloc_size(ctx, hexd_buff_len);
if (!hexd_buff)
return NULL;
- osmo_hexdump_buf(hexd_buff, sizeof(hexd_buff), buf, len, " ", true);
+ osmo_hexdump_buf(hexd_buff, hexd_buff_len, buf, len, " ", true);
return hexd_buff;
}
@@ -389,10 +390,11 @@ char *osmo_hexdump_nospc(const unsigned char *buf, int len)
*/
char *osmo_hexdump_nospc_c(const void *ctx, const unsigned char *buf, int len)
{
- char *hexd_buff = talloc_size(ctx, len*2 + 1);
+ size_t hexd_buff_len = len * 2 + 1;
+ char *hexd_buff = talloc_size(ctx, hexd_buff_len);
if (!hexd_buff)
return NULL;
- osmo_hexdump_buf(hexd_buff, sizeof(hexd_buff), buf, len, "", true);
+ osmo_hexdump_buf(hexd_buff, hexd_buff_len, buf, len, "", true);
return hexd_buff;
}
@@ -908,10 +910,11 @@ const char *osmo_str_tolower(const char *src)
*/
char *osmo_str_tolower_c(const void *ctx, const char *src)
{
- char *buf = talloc_size(ctx, strlen(src)+1);
+ size_t buf_len = strlen(src) + 1;
+ char *buf = talloc_size(ctx, buf_len);
if (!buf)
return NULL;
- osmo_str_tolower_buf(buf, sizeof(buf), src);
+ osmo_str_tolower_buf(buf, buf_len, src);
return buf;
}
@@ -966,10 +969,11 @@ const char *osmo_str_toupper(const char *src)
*/
char *osmo_str_toupper_c(const void *ctx, const char *src)
{
- char *buf = talloc_size(ctx, strlen(src)+1);
+ size_t buf_len = strlen(src) + 1;
+ char *buf = talloc_size(ctx, buf_len);
if (!buf)
return NULL;
- osmo_str_toupper_buf(buf, sizeof(buf), src);
+ osmo_str_toupper_buf(buf, buf_len, src);
return buf;
}