summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2016-10-24 03:22:46 +0000
committerNanang Izzuddin <nanang@teluu.com>2016-10-24 03:22:46 +0000
commit00aa5887abe1fcef80ed2528aaad9f265c599267 (patch)
treeae1a92efe11f84ebb8a68cd0cded995c7279880b
parent49d98191016269301f21542cc24ecf9d1a3c38f4 (diff)
Misc (re #1945): Avoid calling memchr() or memcpy() with NULL pointer (thanks Kal from the patch).
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5468 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjlib/include/pj/string.h2
-rw-r--r--pjlib/include/pj/string_i.h3
-rw-r--r--pjsip/include/pjsip/print_util.h6
-rw-r--r--pjsip/src/pjsip/sip_msg.c2
4 files changed, 9 insertions, 4 deletions
diff --git a/pjlib/include/pj/string.h b/pjlib/include/pj/string.h
index 57c496f3..cfbdd458 100644
--- a/pjlib/include/pj/string.h
+++ b/pjlib/include/pj/string.h
@@ -469,6 +469,8 @@ PJ_IDECL(void) pj_strcat2(pj_str_t *dst, const char *src);
*/
PJ_INLINE(char*) pj_strchr( const pj_str_t *str, int chr)
{
+ if (str->slen == 0)
+ return NULL;
return (char*) memchr((char*)str->ptr, chr, str->slen);
}
diff --git a/pjlib/include/pj/string_i.h b/pjlib/include/pj/string_i.h
index b26d5ead..fd864f3f 100644
--- a/pjlib/include/pj/string_i.h
+++ b/pjlib/include/pj/string_i.h
@@ -120,7 +120,8 @@ PJ_IDEF(pj_str_t*) pj_strncpy( pj_str_t *dst, const pj_str_t *src,
{
pj_assert(max >= 0);
if (max > src->slen) max = src->slen;
- pj_memcpy(dst->ptr, src->ptr, max);
+ if (max > 0)
+ pj_memcpy(dst->ptr, src->ptr, max);
dst->slen = max;
return dst;
}
diff --git a/pjsip/include/pjsip/print_util.h b/pjsip/include/pjsip/print_util.h
index f8f9eb01..bd5d6f6b 100644
--- a/pjsip/include/pjsip/print_util.h
+++ b/pjsip/include/pjsip/print_util.h
@@ -29,8 +29,10 @@
#define copy_advance_check(buf,str) \
do { \
if ((str).slen >= (endbuf-buf)) return -1; \
- pj_memcpy(buf, (str).ptr, (str).slen); \
- buf += (str).slen; \
+ if ((str).slen) { \
+ pj_memcpy(buf, (str).ptr, (str).slen); \
+ buf += (str).slen; \
+ } \
} while (0)
#define copy_advance_pair_check(buf,str1,len1,str2) \
diff --git a/pjsip/src/pjsip/sip_msg.c b/pjsip/src/pjsip/sip_msg.c
index b5d2eb5f..a13f80e1 100644
--- a/pjsip/src/pjsip/sip_msg.c
+++ b/pjsip/src/pjsip/sip_msg.c
@@ -2013,7 +2013,7 @@ static int pjsip_via_hdr_print( pjsip_via_hdr *hdr,
*buf++ = ' ';
/* Check if host contains IPv6 */
- if (pj_memchr(hdr->sent_by.host.ptr, ':', hdr->sent_by.host.slen)) {
+ if (pj_strchr(&hdr->sent_by.host, ':')) {
copy_advance_pair_quote_cond(buf, "", 0, hdr->sent_by.host, '[', ']');
} else {
copy_advance_check(buf, hdr->sent_by.host);