Module: kamailio
Branch: master
Commit: 305f884e0981b64eed9a96410d131d8f9a69eb3d
URL:
https://github.com/kamailio/kamailio/commit/305f884e0981b64eed9a96410d131d8…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2020-10-20T13:50:35+02:00
Merge pull request #2519 from gaaf/features/core-str-copy
core: Zero terminate str copies made with (pkg|shm)_str_dup()
---
Modified: src/core/ut.h
---
Diff:
https://github.com/kamailio/kamailio/commit/305f884e0981b64eed9a96410d131d8…
Patch:
https://github.com/kamailio/kamailio/commit/305f884e0981b64eed9a96410d131d8…
---
diff --git a/src/core/ut.h b/src/core/ut.h
index 6ef2e079bc..5fcb245cd8 100644
--- a/src/core/ut.h
+++ b/src/core/ut.h
@@ -748,6 +748,7 @@ static inline int strz2sint(char* _s, int* _r)
/**
* \brief Make a copy of a str structure to a str using shm_malloc
+ * The copy will be zero-terminated
* \param dst destination
* \param src source
* \return 0 on success, -1 on failure
@@ -775,7 +776,7 @@ static inline int shm_str_dup(str* dst, const str* src)
dst->len = src->len;
}
- dst->s = (char*)shm_malloc(dst->len);
+ dst->s = (char*)shm_malloc(dst->len+1);
if (dst->s == NULL) {
SHM_MEM_ERROR;
return -1;
@@ -788,6 +789,7 @@ static inline int shm_str_dup(str* dst, const str* src)
}
memcpy(dst->s, src->s, dst->len);
+ dst->s[dst->len] = 0;
return 0;
}
@@ -848,6 +850,7 @@ static inline char* shm_str2char_dup(str *src)
/**
* \brief Make a copy of a str structure using pkg_malloc
+ * The copy will be zero-terminated
* \param dst destination
* \param src source
* \return 0 on success, -1 on failure
@@ -875,7 +878,7 @@ static inline int pkg_str_dup(str* dst, const str* src)
dst->len = src->len;
}
- dst->s = (char*)pkg_malloc(dst->len);
+ dst->s = (char*)pkg_malloc(dst->len+1);
if (dst->s == NULL) {
PKG_MEM_ERROR;
return -1;
@@ -888,6 +891,7 @@ static inline int pkg_str_dup(str* dst, const str* src)
}
memcpy(dst->s, src->s, dst->len);
+ dst->s[dst->len] = 0;
return 0;
}