From 00aa5887abe1fcef80ed2528aaad9f265c599267 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Mon, 24 Oct 2016 03:22:46 +0000 Subject: 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 --- pjsip/include/pjsip/print_util.h | 6 ++++-- pjsip/src/pjsip/sip_msg.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'pjsip') 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); -- cgit v1.2.3