Replace unsafe string functions such as strcpy, strncpy, strcat, and sprintf with newly implemented pj_ansi_strxcpy, pj_ansi_strxcpy2, and pj_ansi_strxcat

This commit is contained in:
bennylp 2023-03-24 11:11:20 +07:00
parent 2aaad7daf5
commit 5ed9461bbe
75 changed files with 816 additions and 295 deletions

View File

@ -1169,8 +1169,8 @@ static pj_bool_t handle_up_down(cli_telnet_sess *sess, pj_bool_t is_up)
/* Send data */
pj_strcat(&send_data, history);
telnet_sess_send(sess, &send_data);
pj_ansi_strncpy((char*)&sess->rcmd->rbuf, history->ptr,
history->slen);
pj_ansi_strxcpy2((char*)sess->rcmd->rbuf, history,
sizeof(sess->rcmd->rbuf));
sess->rcmd->len = (unsigned)history->slen;
sess->rcmd->cur_pos = sess->rcmd->len;
return PJ_TRUE;

View File

@ -121,7 +121,7 @@ PJ_DEF(pj_status_t) pj_pcap_open(pj_pool_t *pool,
file = PJ_POOL_ZALLOC_T(pool, pj_pcap_file);
pj_ansi_strcpy(file->obj_name, "pcap");
pj_ansi_strxcpy(file->obj_name, "pcap", sizeof(file->obj_name));
status = pj_file_open(pool, path, PJ_O_RDONLY, &file->fd);
if (status != PJ_SUCCESS)

View File

@ -456,7 +456,7 @@ static void build_server_entries(pj_dns_srv_async_query *query_job,
pj_sockaddr_print(&query_job->srv[i].addr[0],
addr, sizeof(addr), 2);
} else
pj_ansi_strcpy(addr, "-");
pj_ansi_strxcpy(addr, "-", sizeof(addr));
PJ_LOG(5,(query_job->objname,
" %d: SRV %d %d %d %.*s (%s)",

View File

@ -67,16 +67,40 @@
#define pj_ansi_strcmp strcmp
#define pj_ansi_strncmp strncmp
#define pj_ansi_strlen strlen
#define pj_ansi_strcpy strcpy
/*#define pj_ansi_strncpy strncpy */
#define pj_ansi_strcat strcat
#if defined(PJ_BAN_STRCPY) && PJ_BAN_STRCPY
/* Use pj_ansi_strxcpy() instead */
# define strcpy error__strcpy_is_banned
# define pj_ansi_strcpy error__strcpy_is_banned
#else
# define pj_ansi_strcpy strcpy
#endif
#if defined(PJ_BAN_STRNCPY) && PJ_BAN_STRNCPY
/* Use pj_ansi_strxcpy() instead */
# define strncpy error__strncpy_is_banned
# define pj_ansi_strncpy error__strncpy_is_banned
#else
# define pj_ansi_strncpy strncpy
#endif
#if defined(PJ_BAN_STRCAT) && PJ_BAN_STRCAT
/* Use pj_ansi_strxcat() instead */
# define strcat error__strcat_is_banned
# define pj_ansi_strcat error__strcat_is_banned
#else
# define pj_ansi_strcat strcat
#endif
#define pj_ansi_strstr strstr
#define pj_ansi_strchr strchr
#define pj_ansi_strcasecmp strcasecmp
#define pj_ansi_stricmp strcasecmp
#define pj_ansi_strncasecmp strncasecmp
#define pj_ansi_strnicmp strncasecmp
#define pj_ansi_sprintf sprintf
#if defined(PJ_BAN_SPRINTF) && PJ_BAN_SPRINTF
/* Use pj_ansi_snprintf() instead */
# define sprintf error__sprintf_is_banned
# define pj_ansi_sprintf error__sprintf_is_banned
#else
# define pj_ansi_sprintf sprintf
#endif
#if defined(PJ_HAS_NO_SNPRINTF) && PJ_HAS_NO_SNPRINTF != 0
# include <pj/types.h>
@ -88,7 +112,13 @@
#endif
#define pj_ansi_snprintf snprintf
#define pj_ansi_vsprintf vsprintf
#if defined(PJ_BAN_VSPRINTF) && PJ_BAN_VSPRINTF
/* Use pj_ansi_vsnprintf() instead */
# define vsprintf error__vsprintf_is_banned
# define pj_ansi_vsprintf error__vsprintf_is_banned
#else
# define pj_ansi_vsprintf vsprintf
#endif
#define pj_ansi_vsnprintf vsnprintf
#define pj_unicode_strcmp wcscmp

View File

@ -940,6 +940,46 @@
# define PJ_HAS_STRICMP_ALNUM 0
#endif
/**
* Prohibit the use of unsafe string functions such as strcpy(), strncpy(),
* strcat(), and vsprintf().
*/
#ifndef PJ_BAN_UNSAFE_STR_FUNCS
# define PJ_BAN_UNSAFE_STR_FUNCS 0
#endif
/**
* Prohibit the use of strcpy() and pj_ansi_strcpy(), use pj_ansi_strxcpy()
* instead.
*/
#ifndef PJ_BAN_STRCPY
# define PJ_BAN_STRCPY PJ_BAN_UNSAFE_STR_FUNCS
#endif
/**
* Prohibit the use of strncpy() and pj_ansi_strncpy(), use pj_ansi_strxcpy()
* instead.
*/
#ifndef PJ_BAN_STRNCPY
# define PJ_BAN_STRNCPY PJ_BAN_UNSAFE_STR_FUNCS
#endif
/**
* Prohibit the use of strcat() and pj_ansi_strcat(), use pj_ansi_strxcat()
* instead.
*/
#ifndef PJ_BAN_STRCAT
# define PJ_BAN_STRCAT PJ_BAN_UNSAFE_STR_FUNCS
#endif
/**
* Prohibit the use of vsprintf() and pj_ansi_vsprintf(),
* use pj_ansi_vsnprintf() instead.
*/
#ifndef PJ_BAN_VSPRINTF
# define PJ_BAN_VSPRINTF PJ_BAN_UNSAFE_STR_FUNCS
#endif
/*
* Warn about obsolete macros.
*

View File

@ -78,7 +78,7 @@ PJ_BEGIN_DECL
* @param len The length of the string buffer.
*/
#define PJ_CHECK_TRUNC_STR(ret, str, len) \
if ((int)(ret) >= (int)(len) || (ret) < 0) pj_ansi_strcpy((str) + (len) - 3, "..")
if ((int)(ret) >= (int)(len) || (ret) < 0) pj_ansi_strxcpy((str) + (len) - 3, "..", 3)
/**
* Create string initializer from a normal C string.
@ -841,64 +841,56 @@ PJ_INLINE(void*) pj_memchr(const void *buf, int c, pj_size_t size)
}
/**
* Copy at most n bytes (including the null char) from source to destination.
* In any case, the destination string will be null terminated.
* Copy the string, or as much of it as fits, into the dest buffer.
* Regardless of whether all characters were copied, the destination
* buffer will be null terminated, unless dst_size is zero which in
* this case nothing will be written to dst and the function will
* return -PJ_ETOOBIG.
*
* @param dst The destination string.
* @param src The source string.
* @param n The size of the destination string.
* @param dst_size The size of the destination string.
*
* @return The destination string
* @return The number of characters copied (not including the trailing NUL) or
* -PJ_ETOOBIG if the destination buffer wasn't big enough,
* -PJ_EINVAL if the dst or src is NULL.
*/
PJ_INLINE(char*) pj_ansi_strncpy(char *dst, const char *src, pj_size_t n)
{
#ifdef __GNUC__
/* Silence these warnings:
* - __builtin_strncpy specified bound equals destination size
* - __builtin_strncpy output may be truncated copying x bytes from a string of length x
*/
# pragma GCC diagnostic push
# if defined(__has_warning)
# if __has_warning("-Wstringop-truncation")
# pragma GCC diagnostic ignored "-Wstringop-truncation"
# endif
# else
# pragma GCC diagnostic ignored "-Wstringop-truncation"
# endif
#endif
strncpy(dst, src, n-1);
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
dst[n-1] = '\0';
return dst;
}
PJ_DECL(int) pj_ansi_strxcpy(char *dst, const char *src, pj_size_t dst_size);
/**
* Copy src0 to destination string, and then concatenate src1 into destination
* string, limiting the total number of bytes written to the destination
* string to n including the null character. In any case, the destination
* string will be null terminated.
* Same as pj_ansi_strxcpy() but takes pj_str_t as the source.
* If src contains null character, copying will stop at the first null
* character in src.
*
* @param dst The destination string.
* @param src The source string.
* @param n The size of the destination string.
* @param dst_size The size of the destination string.
*
* @return The destination string
* @return The number of characters copied (not including the trailing NUL) or
* -PJ_ETOOBIG if the destination buffer wasn't big enough,
* -PJ_EINVAL if the dst or src is NULL.
*/
PJ_INLINE(char*) pj_ansi_safe_strcpycat(char *dst,
const char *src0,
const char *src1,
pj_size_t n)
{
pj_ansi_strncpy(dst, src0, n);
if (src1) {
pj_size_t dst_len = pj_ansi_strlen(dst);
if (dst_len < n-1)
pj_ansi_strncpy(dst+dst_len, src1, n-dst_len);
}
return dst;
}
PJ_DECL(int) pj_ansi_strxcpy2(char *dst, const pj_str_t *src,
pj_size_t dst_size);
/**
* Concatenate src, or as much of it as fits, into the dest buffer.
* Regardless of whether all characters were copied, the destination
* buffer will be null terminated, unless dst_size is zero which in
* this case nothing will be written to dst and the function will
* return -PJ_ETOOBIG.
*
* @param dst The destination string.
* @param src The source string.
* @param dst_size The size of the destination string.
*
* @return Final length of dst string (not including the trailing NUL) or
* -PJ_ETOOBIG if the destination buffer wasn't big enough,
* -PJ_EINVAL if the dst or src is NULL.
*/
PJ_DECL(int) pj_ansi_strxcat(char *dst, const char *src, pj_size_t dst_size);
/**
* @}

View File

@ -146,7 +146,8 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename,
continue;
/* Store canonical name */
pj_ansi_strcpy(ai[i].ai_canonname, nodecopy);
pj_ansi_strxcpy(ai[i].ai_canonname, nodecopy,
sizeof(ai[i].ai_canonname));
/* Store address */
addr_size = sizeof(*addr);
@ -220,10 +221,11 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename,
/* Store canonical name (possibly truncating the name) */
if (res->ai_canonname) {
pj_ansi_strncpy(ai[i].ai_canonname, res->ai_canonname,
pj_ansi_strxcpy(ai[i].ai_canonname, res->ai_canonname,
sizeof(ai[i].ai_canonname));
} else {
pj_ansi_strcpy(ai[i].ai_canonname, nodecopy);
pj_ansi_strxcpy(ai[i].ai_canonname, nodecopy,
sizeof(ai[i].ai_canonname));
}
/* Store address */
@ -302,7 +304,7 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename,
pj_bzero(ai, max_count * sizeof(pj_addrinfo));
for (i=0; he.h_addr_list[i] && *count<max_count; ++i) {
pj_ansi_strncpy(ai[*count].ai_canonname, he.h_name,
pj_ansi_strxcpy(ai[*count].ai_canonname, he.h_name,
sizeof(ai[*count].ai_canonname));
ai[*count].ai_addr.ipv4.sin_family = PJ_AF_INET;

View File

@ -234,7 +234,7 @@ static void pj_perror_imp(int log_level, const char *sender,
/* Build the title */
len = pj_ansi_vsnprintf(titlebuf, sizeof(titlebuf), title_fmt, marker);
if (len < 0 || len >= (int)sizeof(titlebuf))
pj_ansi_strcpy(titlebuf, "Error");
pj_ansi_strxcpy(titlebuf, "Error", sizeof(titlebuf));
/* Get the error */
pj_strerror(status, errmsg, sizeof(errmsg));

View File

@ -306,7 +306,7 @@ static pj_status_t if_enum_by_af(int af, unsigned *p_cnt, pj_sockaddr ifs[])
struct sockaddr *ad;
int rc;
pj_ansi_strncpy(ifreq.ifr_name, if_list[i].if_name, IFNAMSIZ);
pj_ansi_strxcpy(ifreq.ifr_name, if_list[i].if_name, IFNAMSIZ);
TRACE_((THIS_FILE, " checking interface %s", ifreq.ifr_name));

View File

@ -368,13 +368,13 @@ PJ_DEF(void) pj_log( const char *sender, int level,
if (log_decor & PJ_LOG_HAS_LEVEL_TEXT) {
static const char *ltexts[] = { "FATAL:", "ERROR:", " WARN:",
" INFO:", "DEBUG:", "TRACE:", "DETRC:"};
pj_ansi_strcpy(pre, ltexts[level]);
pj_ansi_strxcpy(pre, ltexts[level], PJ_LOG_MAX_SIZE);
pre += 6;
}
if (log_decor & PJ_LOG_HAS_DAY_NAME) {
static const char *wdays[] = { "Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"};
pj_ansi_strcpy(pre, wdays[ptime.wday]);
pj_ansi_strxcpy(pre, wdays[ptime.wday], PJ_LOG_MAX_SIZE-6);
pre += 3;
}
if (log_decor & PJ_LOG_HAS_YEAR) {

View File

@ -725,7 +725,7 @@ PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool,
if (strchr(thread_name, '%')) {
pj_ansi_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec);
} else {
pj_ansi_strncpy(rec->obj_name, thread_name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(rec->obj_name, thread_name, PJ_MAX_OBJ_NAME);
}
/* Set default stack size */
@ -1351,7 +1351,7 @@ static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name, int type)
if (strchr(name, '%')) {
pj_ansi_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex);
} else {
pj_ansi_strncpy(mutex->obj_name, name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(mutex->obj_name, name, PJ_MAX_OBJ_NAME);
}
PJ_LOG(6, (mutex->obj_name, "Mutex created"));
@ -1435,7 +1435,8 @@ PJ_DEF(pj_status_t) pj_mutex_lock(pj_mutex_t *mutex)
#if PJ_DEBUG
if (status == PJ_SUCCESS) {
mutex->owner = pj_thread_this();
pj_ansi_strcpy(mutex->owner_name, mutex->owner->obj_name);
pj_ansi_strxcpy(mutex->owner_name, mutex->owner->obj_name,
sizeof(mutex->owner_name));
++mutex->nesting_level;
}
@ -1518,7 +1519,8 @@ PJ_DEF(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex)
if (status==0) {
#if PJ_DEBUG
mutex->owner = pj_thread_this();
pj_ansi_strcpy(mutex->owner_name, mutex->owner->obj_name);
pj_ansi_strxcpy(mutex->owner_name, mutex->owner->obj_name,
sizeof(mutex->owner_name));
++mutex->nesting_level;
PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s (level=%d)",
@ -1770,7 +1772,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
if (strchr(name, '%')) {
pj_ansi_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem);
} else {
pj_ansi_strncpy(sem->obj_name, name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(sem->obj_name, name, PJ_MAX_OBJ_NAME);
}
PJ_LOG(6, (sem->obj_name, "Semaphore created"));
@ -2080,45 +2082,45 @@ PJ_DEF(pj_status_t) pj_term_set_color(pj_color_t color)
if (color & PJ_TERM_COLOR_BRIGHT) {
color ^= PJ_TERM_COLOR_BRIGHT;
} else {
strcpy(ansi_color, "\033[00;3");
pj_ansi_strxcpy(ansi_color, "\033[00;3", sizeof(ansi_color));
}
switch (color) {
case 0:
/* black color */
strcat(ansi_color, "0m");
pj_ansi_strxcat(ansi_color, "0m", sizeof(ansi_color));
break;
case PJ_TERM_COLOR_R:
/* red color */
strcat(ansi_color, "1m");
pj_ansi_strxcat(ansi_color, "1m", sizeof(ansi_color));
break;
case PJ_TERM_COLOR_G:
/* green color */
strcat(ansi_color, "2m");
pj_ansi_strxcat(ansi_color, "2m", sizeof(ansi_color));
break;
case PJ_TERM_COLOR_B:
/* blue color */
strcat(ansi_color, "4m");
pj_ansi_strxcat(ansi_color, "4m", sizeof(ansi_color));
break;
case PJ_TERM_COLOR_R | PJ_TERM_COLOR_G:
/* yellow color */
strcat(ansi_color, "3m");
pj_ansi_strxcat(ansi_color, "3m", sizeof(ansi_color));
break;
case PJ_TERM_COLOR_R | PJ_TERM_COLOR_B:
/* magenta color */
strcat(ansi_color, "5m");
pj_ansi_strxcat(ansi_color, "5m", sizeof(ansi_color));
break;
case PJ_TERM_COLOR_G | PJ_TERM_COLOR_B:
/* cyan color */
strcat(ansi_color, "6m");
pj_ansi_strxcat(ansi_color, "6m", sizeof(ansi_color));
break;
case PJ_TERM_COLOR_R | PJ_TERM_COLOR_G | PJ_TERM_COLOR_B:
/* white color */
strcat(ansi_color, "7m");
pj_ansi_strxcat(ansi_color, "7m", sizeof(ansi_color));
break;
default:
/* default console color */
strcpy(ansi_color, "\033[00m");
pj_ansi_strxcpy(ansi_color, "\033[00m", sizeof(ansi_color));
break;
}

View File

@ -581,7 +581,7 @@ PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool,
if (strchr(thread_name, '%')) {
pj_ansi_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec);
} else {
pj_ansi_strncpy(rec->obj_name, thread_name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(rec->obj_name, thread_name, PJ_MAX_OBJ_NAME);
}
PJ_LOG(6, (rec->obj_name, "Thread created"));
@ -1017,7 +1017,7 @@ static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name)
if (strchr(name, '%')) {
pj_ansi_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex);
} else {
pj_ansi_strncpy(mutex->obj_name, name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(mutex->obj_name, name, PJ_MAX_OBJ_NAME);
}
PJ_LOG(6, (mutex->obj_name, "Mutex created"));
@ -1267,7 +1267,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
if (strchr(name, '%')) {
pj_ansi_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem);
} else {
pj_ansi_strncpy(sem->obj_name, name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(sem->obj_name, name, PJ_MAX_OBJ_NAME);
}
LOG_MUTEX((sem->obj_name, "Semaphore created"));
@ -1407,7 +1407,7 @@ PJ_DEF(pj_status_t) pj_event_create( pj_pool_t *pool,
if (strchr(name, '%')) {
pj_ansi_snprintf(event->obj_name, PJ_MAX_OBJ_NAME, name, event);
} else {
pj_ansi_strncpy(event->obj_name, name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(event->obj_name, name, PJ_MAX_OBJ_NAME);
}
PJ_LOG(6, (event->obj_name, "Event created"));

View File

@ -177,7 +177,7 @@ PJ_DEF(void) pj_pool_init_int( pj_pool_t *pool,
pj_ansi_snprintf(pool->obj_name, sizeof(pool->obj_name),
name, pool);
} else {
pj_ansi_strncpy(pool->obj_name, name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(pool->obj_name, name, PJ_MAX_OBJ_NAME);
}
} else {
pool->obj_name[0] = '\0';

View File

@ -72,9 +72,9 @@ PJ_DEF(pj_pool_t*) pj_pool_create_imp( const char *file, int line,
return NULL;
if (name) {
pj_ansi_strncpy(pool->obj_name, name, sizeof(pool->obj_name));
pj_ansi_strxcpy(pool->obj_name, name, sizeof(pool->obj_name));
} else {
strcpy(pool->obj_name, "altpool");
pj_ansi_strxcpy(pool->obj_name, "altpool", sizeof(pool->obj_name));
}
pool->factory = NULL;

View File

@ -180,7 +180,7 @@ static pj_str_t tls_strerror(pj_status_t status,
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
if (tmp) {
pj_ansi_strncpy(buf, tmp, bufsize);
pj_ansi_strxcpy(buf, tmp, bufsize);
errstr = pj_str(buf);
return errstr;
}

View File

@ -191,7 +191,7 @@ static void update_certs_info(pj_ssl_sock_t* ssock,
# ifdef _MSC_VER
# define strerror_r(err,buf,len) strerror_s(buf,len,err)
# else
# define strerror_r(err,buf,len) pj_ansi_strncpy(buf,strerror(err),len)
# define strerror_r(err,buf,len) pj_ansi_strxcpy(buf,strerror(err),len)
# endif
#endif
@ -441,7 +441,7 @@ static pj_str_t ssl_strerror(pj_status_t status,
const char *tmp = NULL;
tmp = ERR_reason_error_string(ssl_err);
if (tmp) {
pj_ansi_strncpy(buf, tmp, bufsize);
pj_ansi_strxcpy(buf, tmp, bufsize);
errstr = pj_str(buf);
return errstr;
}

View File

@ -513,3 +513,71 @@ PJ_DEF(int) pj_utoa_pad( unsigned long val, char *buf, int min_dig, int pad)
return len;
}
PJ_DEF(int) pj_ansi_strxcpy(char *dst, const char *src,
pj_size_t dst_size)
{
char *odst = dst;
PJ_ASSERT_RETURN(dst && src, -PJ_EINVAL);
if (dst_size==0)
return -PJ_ETOOBIG;
while (--dst_size && (*dst=*src) != 0) {
++dst;
++src;
}
if (!*dst && !*src) {
return dst-odst;
} else {
*dst = '\0';
return *src? -PJ_ETOOBIG : dst-odst;
}
}
PJ_DEF(int) pj_ansi_strxcpy2(char *dst, const pj_str_t *src,
pj_size_t dst_size)
{
char *odst = dst;
const char *ssrc, *esrc;
PJ_ASSERT_RETURN(dst && src && src->slen >= 0, -PJ_EINVAL);
if (dst_size==0)
return -PJ_ETOOBIG;
ssrc = src->ptr;
esrc = ssrc + src->slen;
while (ssrc < esrc && --dst_size && (*dst = *ssrc)!= 0) {
dst++;
ssrc++;
}
*dst = '\0';
if (ssrc==esrc || !*ssrc) {
return dst-odst;
} else {
return -PJ_ETOOBIG;
}
}
PJ_DEF(int) pj_ansi_strxcat(char *dst, const char *src, pj_size_t dst_size)
{
pj_size_t dst_len;
PJ_ASSERT_RETURN(dst && src, -PJ_EINVAL);
if (dst_size==0)
return -PJ_ETOOBIG;
dst_len = pj_ansi_strlen(dst);
if (dst_len < dst_size) {
int rc = pj_ansi_strxcpy(dst+dst_len, src, dst_size-dst_len);
if (rc < 0)
return rc;
return dst_len + rc;
} else
return -PJ_ETOOBIG;
}

View File

@ -517,9 +517,9 @@ static int send_recv_test(int sock_type,
return -151;
if (pj_sockaddr_cmp(&addr, srcaddr) != 0) {
char srcaddr_str[32], addr_str[32];
pj_ansi_strncpy(srcaddr_str, pj_inet_ntoa(srcaddr->sin_addr),
pj_ansi_strxcpy(srcaddr_str, pj_inet_ntoa(srcaddr->sin_addr),
sizeof(srcaddr_str));
pj_ansi_strncpy(addr_str, pj_inet_ntoa(addr.sin_addr),
pj_ansi_strxcpy(addr_str, pj_inet_ntoa(addr.sin_addr),
sizeof(addr_str));
PJ_LOG(3,("test", "...error: src address mismatch (original=%s, "
"recvfrom addr=%s)",

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <pj/string.h>
#include <pj/assert.h>
#include <pj/errno.h>
#include <pj/pool.h>
#include <pj/log.h>
#include <pj/os.h>
@ -289,6 +291,324 @@ static int strcmp_test(void)
#undef STR_TEST
}
static int verify_strxcpy(const char *src, int dst_size, int exp_ret,
const char *exp_dst)
{
char dst[6];
char GUARD = '@';
int i, ret;
PJ_ASSERT_RETURN(src && dst_size <= 5, -700);
memset(dst, GUARD, sizeof(dst));
ret = pj_ansi_strxcpy(dst, src, dst_size);
/* verify return value */
if (ret != exp_ret) {
PJ_LOG(3,("", " strxcpy \"%s\", dst_size=%d: ret %d != %d",
src, dst_size, ret, exp_ret));
return -704;
}
/* expected dst content */
if (exp_dst) {
if (strcmp(dst, exp_dst)) {
PJ_LOG(3,("", " strxcpy \"%s\", dst_size=%d: dst content mismatch: \"%s\"!=\"%s\"",
src, dst_size, dst, exp_dst));
return -708;
}
}
/* verify not writing pass buffer */
for (i=exp_dst?strlen(exp_dst)+1:0; i<sizeof(dst); ++i) {
if (dst[i] != GUARD) {
PJ_LOG(3,("", " strxcpy \"%s\", dst_size=%d: overflow at %d",
src, dst_size, i));
return -710;
}
}
return 0;
}
static int strxcpy_test(void)
{
int rc;
#define CHECK_(src, dst_size, exp_ret, exp_dst) \
rc = verify_strxcpy(src, dst_size, exp_ret, exp_dst); \
if (rc) return rc
CHECK_( "", 0, -PJ_ETOOBIG, NULL);
CHECK_( "a", 0, -PJ_ETOOBIG, NULL);
{
/* special test 1 (dst contains null) */
char dst[4];
pj_bzero(dst, sizeof(dst));
rc = pj_ansi_strxcpy(dst, "a", 1);
if (rc != -PJ_ETOOBIG) {
PJ_LOG(3,("", " pj_ansi_strxcpy special test 1: ret %d!=%d",
rc, -PJ_ETOOBIG));
return -700;
}
}
CHECK_( "", 1, 0, "");
CHECK_( "a", 1, -PJ_ETOOBIG, "");
CHECK_( "ab", 1, -PJ_ETOOBIG, "");
CHECK_( "abcd", 1, -PJ_ETOOBIG, "");
CHECK_( "abc", 2, -PJ_ETOOBIG, "a");
CHECK_( "ab", 2, -PJ_ETOOBIG, "a");
CHECK_( "a", 2, 1, "a");
CHECK_( "", 2, 0, "");
CHECK_( "abcd", 3, -PJ_ETOOBIG, "ab");
CHECK_( "abc", 3, -PJ_ETOOBIG, "ab");
CHECK_( "ab", 3, 2, "ab");
CHECK_( "a", 3, 1, "a");
CHECK_( "", 3, 0, "");
CHECK_( "abcde", 4, -PJ_ETOOBIG, "abc");
CHECK_( "abcd", 4, -PJ_ETOOBIG, "abc");
CHECK_( "abc", 4, 3, "abc");
CHECK_( "ab", 4, 2, "ab");
CHECK_( "a", 4, 1, "a");
CHECK_( "", 4, 0, "");
CHECK_( "abcdef", 5, -PJ_ETOOBIG, "abcd");
CHECK_( "abcde", 5, -PJ_ETOOBIG, "abcd");
CHECK_( "abcd", 5, 4, "abcd");
CHECK_( "abc", 5, 3, "abc");
CHECK_( "ab", 5, 2, "ab");
CHECK_( "a", 5, 1, "a");
CHECK_( "", 5, 0, "");
#undef CHECK_
return 0;
}
static int verify_strxcpy2(const pj_str_t *src, int dst_size, int exp_ret,
const char *exp_dst)
{
char dst[6];
char GUARD = '@';
int i, ret;
PJ_ASSERT_RETURN(src && dst_size <= 5, -720);
memset(dst, GUARD, sizeof(dst));
ret = pj_ansi_strxcpy2(dst, src, dst_size);
/* verify return value */
if (ret != exp_ret) {
PJ_LOG(3,("", " strxcpy2 \"%.*s\" slen=%ld, dst_size=%d: ret %d!=%d",
(int)src->slen, src->ptr, src->slen, dst_size, ret, exp_ret));
return -724;
}
/* expected dst content */
if (exp_dst) {
if (strcmp(dst, exp_dst)) {
PJ_LOG(3,("", " strxcpy2 \"%.*s\" slen=%ld, dst_size=%d: "
"dst content mismatch: \"%s\"!=\"%s\"",
(int)src->slen, src->ptr, src->slen, dst_size, dst,
exp_dst));
return -726;
}
}
/* verify not writing pass buffer */
for (i=dst_size; i<sizeof(dst); ++i) {
if (dst[i] != GUARD) {
PJ_LOG(3,("", " strxcpy2 \"%.*s\" slen=%ld, dst_size=%d: "
"overflow at %d (chr %d)",
(int)src->slen, src->ptr, src->slen, dst_size, i,
(char)(dst[i] & 0xFF)));
return -728;
}
}
return 0;
}
static int strxcpy2_test(void)
{
pj_str_t src;
char nulls[6];
int rc;
pj_bzero(nulls, sizeof(nulls));
#define CHECK2_(s, src_len, dst_size, exp_ret, exp_dst) \
src.ptr = s; src.slen = src_len; \
rc = verify_strxcpy2(&src, dst_size, exp_ret, exp_dst); \
if (rc) return rc
CHECK2_( NULL, 0, 0, -PJ_ETOOBIG, NULL);
CHECK2_( "a!", 1, 0, -PJ_ETOOBIG, NULL);
CHECK2_( "abc!", 3, 1, -PJ_ETOOBIG, "");
CHECK2_( "ab!", 2, 1, -PJ_ETOOBIG, "");
/* note for test below: although src contains null and the strlen
of result (i.e. dst) is zero, strxcpy2 would still return
-PJ_ETOOBIG because the required buffer size is assumed to
be 2 (one for the src->ptr content (although the content is a
null character), one for the null terminator)
*/
CHECK2_( nulls, 1, 1, 0, "");
CHECK2_( "a!", 1, 1, -PJ_ETOOBIG, "");
CHECK2_( "a", 1, 1, -PJ_ETOOBIG, "");
CHECK2_( "", 0, 1, 0, "");
CHECK2_( NULL, 0, 1, 0, "");
CHECK2_( "abc", 3, 2, -PJ_ETOOBIG, "a");
CHECK2_( "ab", 2, 2, -PJ_ETOOBIG, "a");
CHECK2_( "a!", 1, 2, 1, "a");
CHECK2_( nulls, 1, 2, 0, "");
CHECK2_( "!", 0, 2, 0, "");
CHECK2_( NULL, 0, 2, 0, "");
CHECK2_( "abc", 3, 3, -PJ_ETOOBIG, "ab");
CHECK2_( "ab", 3, 3, 2, "ab");
CHECK2_( nulls, 3, 3, 0, "");
CHECK2_( "abc", 2, 3, 2, "ab");
CHECK2_( "ab", 2, 3, 2, "ab");
CHECK2_( "a", 2, 3, 1, "a");
CHECK2_( nulls, 2, 3, 0, "");
CHECK2_( "a", 1, 3, 1, "a");
CHECK2_( "", 1, 3, 0, "");
CHECK2_( "", 0, 3, 0, "");
CHECK2_( NULL, 0, 3, 0, "");
CHECK2_( "abcde",5, 4, -PJ_ETOOBIG, "abc");
CHECK2_( "abcd", 4, 4, -PJ_ETOOBIG, "abc");
CHECK2_( "abc", 4, 4, 3, "abc");
CHECK2_( "ab", 4, 4, 2, "ab");
CHECK2_( "a", 4, 4, 1, "a");
CHECK2_( nulls, 4, 4, 0, "");
CHECK2_( "abc", 3, 4, 3, "abc");
CHECK2_( "ab", 3, 4, 2, "ab");
CHECK2_( "ab", 2, 4, 2, "ab");
CHECK2_( "a", 2, 4, 1, "a");
CHECK2_( "", 2, 4, 0, "");
CHECK2_( nulls, 2, 4, 0, "");
CHECK2_( "a", 1, 4, 1, "a");
CHECK2_( nulls, 1, 4, 0, "");
CHECK2_( "a", 0, 4, 0, "");
CHECK2_( "", 0, 4, 0, "");
CHECK2_( NULL, 0, 4, 0, "");
#undef CHECK2_
return 0;
}
static int verify_strxcat(const char *cdst, const char *src, int dst_size,
int exp_ret, const char *exp_dst)
{
char dst[6];
char GUARD = '@';
int i, ret;
PJ_ASSERT_RETURN(src && strlen(cdst) <= 4, -730);
PJ_ASSERT_RETURN(strlen(cdst) < dst_size ||
(strlen(cdst)==0 && dst_size==0), -731);
memset(dst, GUARD, sizeof(dst));
if (dst_size) {
ret = pj_ansi_strxcpy(dst, cdst, dst_size);
PJ_ASSERT_RETURN(ret==strlen(cdst), -732);
}
ret = pj_ansi_strxcat(dst, src, dst_size);
/* verify return value */
if (ret != exp_ret) {
PJ_LOG(3,("", " strxcat \"%s\", \"%s\", dst_size=%d: ret %d!=%d",
cdst, src, dst_size, ret, exp_ret));
return -734;
}
/* expected dst content */
if (exp_dst) {
if (strcmp(dst, exp_dst)) {
PJ_LOG(3,("", " strxcat \"%s\", \"%s\", dst_size=%d: "
"dst content mismatch: \"%s\"!=\"%s\"",
cdst, src, dst_size, dst, exp_dst));
return -736;
}
}
/* verify not writing past buffer */
for (i=exp_dst?strlen(exp_dst)+1:0; i<sizeof(dst); ++i) {
if (dst[i] != GUARD) {
PJ_LOG(3,("", " strxcat \"%s\", \"%s\", dst_size=%d: "
"overflow at %d",
cdst, src, dst_size, i));
return -738;
}
}
return 0;
}
static int strxcat_test(void)
{
int rc;
#define CHECK3_(dst, src, dst_size, exp_ret, exp_dst) \
rc = verify_strxcat(dst, src, dst_size, exp_ret, exp_dst); \
if (rc) return rc
CHECK3_( "", "", 0, -PJ_ETOOBIG, NULL);
CHECK3_( "", "a", 0, -PJ_ETOOBIG, NULL);
CHECK3_( "", "", 1, 0, "");
CHECK3_( "", "a", 1, -PJ_ETOOBIG, "");
CHECK3_( "", "a", 2, 1, "a");
CHECK3_( "", "ab", 2, -PJ_ETOOBIG, "a");
CHECK3_( "0", "", 2, 1, "0");
CHECK3_( "0", "a", 2, -PJ_ETOOBIG, "0");
CHECK3_( "", "a", 3, 1, "a");
CHECK3_( "", "ab", 3, 2, "ab");
CHECK3_( "", "abc", 3, -PJ_ETOOBIG, "ab");
CHECK3_( "0", "", 3, 1, "0");
CHECK3_( "0", "a", 3, 2, "0a");
CHECK3_( "0", "ab", 3, -PJ_ETOOBIG, "0a");
CHECK3_( "01", "", 3, 2, "01");
CHECK3_( "01", "a", 3, -PJ_ETOOBIG, "01");
CHECK3_( "01", "ab", 3, -PJ_ETOOBIG, "01");
CHECK3_( "", "a", 4, 1, "a");
CHECK3_( "", "ab", 4, 2, "ab");
CHECK3_( "", "abc", 4, 3, "abc");
CHECK3_( "", "abcd", 4, -PJ_ETOOBIG, "abc");
CHECK3_( "0", "", 4, 1, "0");
CHECK3_( "0", "a", 4, 2, "0a");
CHECK3_( "0", "ab", 4, 3, "0ab");
CHECK3_( "0", "abc", 4, -PJ_ETOOBIG, "0ab");
CHECK3_( "01", "", 4, 2, "01");
CHECK3_( "01", "a", 4, 3, "01a");
CHECK3_( "01", "ab", 4, -PJ_ETOOBIG, "01a");
CHECK3_( "01", "abc", 4, -PJ_ETOOBIG, "01a");
CHECK3_( "012", "", 4, 3, "012");
CHECK3_( "012", "a", 4, -PJ_ETOOBIG, "012");
CHECK3_( "012", "ab", 4, -PJ_ETOOBIG, "012");
CHECK3_( "012", "abc",4, -PJ_ETOOBIG, "012");
#undef CHECK3_
return 0;
}
int string_test(void)
{
const pj_str_t hello_world = { HELLO_WORLD, HELLO_WORLD_LEN };
@ -425,6 +745,21 @@ int string_test(void)
if (i != 0)
return i;
/* strxcpy test */
i = strxcpy_test();
if (i != 0)
return i;
/* strxcpy2 test */
i = strxcpy2_test();
if (i != 0)
return i;
/* strxcat test */
i = strxcat_test();
if (i != 0)
return i;
return 0;
}

View File

@ -258,7 +258,7 @@ static pj_status_t add_dev (struct alsa_factory *af, const char *dev_name)
pj_bzero(adi, sizeof(*adi));
/* Set device name */
pj_ansi_strncpy(adi->name, dev_name, sizeof(adi->name));
pj_ansi_strxcpy(adi->name, dev_name, sizeof(adi->name));
/* Check the number of playback channels */
adi->output_count = (pb_result>=0) ? 1 : 0;
@ -270,7 +270,7 @@ static pj_status_t add_dev (struct alsa_factory *af, const char *dev_name)
adi->default_samples_per_sec = 8000;
/* Driver name */
strcpy(adi->driver, "ALSA");
pj_ansi_strxcpy(adi->driver, "ALSA", sizeof(adi->driver));
++af->dev_cnt;
@ -311,14 +311,14 @@ static void get_mixer_name(struct alsa_factory *af)
{
if (snd_mixer_selem_has_playback_volume(elem))
{
pj_ansi_strncpy(af->pb_mixer_name, elemname,
pj_ansi_strxcpy(af->pb_mixer_name, elemname,
sizeof(af->pb_mixer_name));
TRACE_((THIS_FILE, "Playback mixer name: %s",
af->pb_mixer_name));
}
if (snd_mixer_selem_has_capture_volume(elem))
{
pj_ansi_strncpy(af->cap_mixer_name, elemname,
pj_ansi_strxcpy(af->cap_mixer_name, elemname,
sizeof(af->cap_mixer_name));
TRACE_((THIS_FILE, "Capture mixer name: %s",
af->cap_mixer_name));

View File

@ -174,7 +174,7 @@ static pj_status_t factory_get_dev_info(pjmedia_aud_dev_factory *f,
return PJMEDIA_EAUD_INVDEV;
pj_bzero(info, sizeof(*info));
pj_ansi_strncpy(info->name, si->name, sizeof(info->name));
pj_ansi_strxcpy(info->name, si->name, sizeof(info->name));
info->input_count = si->input_count;
info->output_count = si->output_count;
info->default_samples_per_sec = si->default_samples_per_sec;

View File

@ -417,8 +417,8 @@ static pj_status_t oboe_refresh(pjmedia_aud_dev_factory *ff)
jni_env->GetObjectField(jdev_info,
jobjs.dev_info.f_name);
const char *strtmp = jni_env->GetStringUTFChars(jstrtmp, NULL);
pj_ansi_strncpy(base_adi->name, strtmp, sizeof(base_adi->name));
pj_ansi_strncpy(base_adi->driver, DRIVER_NAME,
pj_ansi_strxcpy(base_adi->name, strtmp, sizeof(base_adi->name));
pj_ansi_strxcpy(base_adi->driver, DRIVER_NAME,
sizeof(base_adi->driver));
f->dev_count++;

View File

@ -519,11 +519,11 @@ static pj_status_t pa_get_dev_info(pjmedia_aud_dev_factory *f,
return PJMEDIA_EAUD_INVDEV;
pj_bzero(info, sizeof(*info));
pj_ansi_strncpy(info->name, pa_info->name, sizeof(info->name));
pj_ansi_strxcpy(info->name, pa_info->name, sizeof(info->name));
info->input_count = pa_info->maxInputChannels;
info->output_count = pa_info->maxOutputChannels;
info->default_samples_per_sec = (unsigned)pa_info->defaultSampleRate;
pj_ansi_strncpy(info->driver, DRIVER_NAME, sizeof(info->driver));
pj_ansi_strxcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
info->caps = PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY |
PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY;

View File

@ -330,13 +330,13 @@ static void build_dev_info(UINT deviceId, struct wmme_dev_info *wdi,
/* Device Name */
if (deviceId==WAVE_MAPPER) {
pj_ansi_strncpy(wdi->info.name, "Wave mapper",
pj_ansi_strxcpy(wdi->info.name, "Wave mapper",
sizeof(wdi->info.name));
} else {
const pj_char_t *szPname = WIC_WOC(wic, woc, szPname);
PJ_DECL_ANSI_TEMP_BUF(wTmp, sizeof(wdi->info.name));
pj_ansi_strncpy(wdi->info.name,
pj_ansi_strxcpy(wdi->info.name,
PJ_NATIVE_TO_STRING(szPname, wTmp, PJ_ARRAY_SIZE(wTmp)),
sizeof(wdi->info.name));
}

View File

@ -540,12 +540,12 @@ static pj_status_t and_factory_refresh(pjmedia_vid_dev_factory *ff)
PJMEDIA_VID_DEV_CAP_ORIENTATION;
/* Set driver & name info */
pj_ansi_strncpy(vdi->driver, "Android", sizeof(vdi->driver));
pj_ansi_strxcpy(vdi->driver, "Android", sizeof(vdi->driver));
adi->facing = facing;
if (facing == 0) {
pj_ansi_strncpy(vdi->name, "Back camera", sizeof(vdi->name));
pj_ansi_strxcpy(vdi->name, "Back camera", sizeof(vdi->name));
} else {
pj_ansi_strncpy(vdi->name, "Front camera", sizeof(vdi->name));
pj_ansi_strxcpy(vdi->name, "Front camera", sizeof(vdi->name));
}
/* Get supported sizes */

View File

@ -281,8 +281,8 @@ static void reset_dev_info(struct avi_dev_info *adi)
pj_bzero(adi, sizeof(*adi));
/* Fill up with *dummy" device info */
pj_ansi_strncpy(adi->info.name, "AVI Player", sizeof(adi->info.name));
pj_ansi_strncpy(adi->info.driver, DRIVER_NAME,
pj_ansi_strxcpy(adi->info.name, "AVI Player", sizeof(adi->info.name));
pj_ansi_strxcpy(adi->info.driver, DRIVER_NAME,
sizeof(adi->info.driver));
adi->info.dir = PJMEDIA_DIR_CAPTURE;
adi->info.has_callback = PJ_FALSE;
@ -488,9 +488,9 @@ PJ_DEF(pj_status_t) pjmedia_avi_dev_alloc( pjmedia_vid_dev_factory *f,
}
/* Init device info */
pj_ansi_strncpy(adi->info.name, adi->title.ptr,
pj_ansi_strxcpy(adi->info.name, adi->title.ptr,
sizeof(adi->info.name));
pj_ansi_strncpy(adi->info.driver, DRIVER_NAME,
pj_ansi_strxcpy(adi->info.driver, DRIVER_NAME,
sizeof(adi->info.driver));
adi->info.dir = PJMEDIA_DIR_CAPTURE;
adi->info.has_callback = PJ_FALSE;

View File

@ -201,9 +201,9 @@ static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f)
/* Passive capturer */
ddi = &cf->dev_info[0];
pj_bzero(ddi, sizeof(*ddi));
pj_ansi_strncpy(ddi->info.name, "Colorbar generator",
pj_ansi_strxcpy(ddi->info.name, "Colorbar generator",
sizeof(ddi->info.name));
pj_ansi_strncpy(ddi->info.driver, "Colorbar",
pj_ansi_strxcpy(ddi->info.driver, "Colorbar",
sizeof(ddi->info.driver));
ddi->info.dir = PJMEDIA_DIR_CAPTURE;
ddi->info.has_callback = PJ_FALSE;
@ -220,9 +220,9 @@ static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f)
/* Active capturer */
ddi = &cf->dev_info[1];
pj_bzero(ddi, sizeof(*ddi));
pj_ansi_strncpy(ddi->info.name, "Colorbar-active",
pj_ansi_strxcpy(ddi->info.name, "Colorbar-active",
sizeof(ddi->info.name));
pj_ansi_strncpy(ddi->info.driver, "Colorbar",
pj_ansi_strxcpy(ddi->info.driver, "Colorbar",
sizeof(ddi->info.driver));
ddi->info.dir = PJMEDIA_DIR_CAPTURE;
ddi->info.has_callback = PJ_TRUE;

View File

@ -302,8 +302,8 @@ static pj_status_t darwin_factory_refresh(pjmedia_vid_dev_factory *f)
/* Init output device */
qdi = &qf->dev_info[qf->dev_count++];
pj_bzero(qdi, sizeof(*qdi));
pj_ansi_strncpy(qdi->info.name, "UIView", sizeof(qdi->info.name));
pj_ansi_strncpy(qdi->info.driver, "iOS", sizeof(qdi->info.driver));
pj_ansi_strxcpy(qdi->info.name, "UIView", sizeof(qdi->info.name));
pj_ansi_strxcpy(qdi->info.driver, "iOS", sizeof(qdi->info.driver));
qdi->info.dir = PJMEDIA_DIR_RENDER;
qdi->info.has_callback = PJ_FALSE;
#endif
@ -361,10 +361,10 @@ static pj_status_t darwin_factory_refresh(pjmedia_vid_dev_factory *f)
qdi = &qf->dev_info[qf->dev_count++];
pj_bzero(qdi, sizeof(*qdi));
pj_ansi_strncpy(qdi->info.name,
pj_ansi_strxcpy(qdi->info.name,
[device.localizedName UTF8String],
sizeof(qdi->info.name));
pj_ansi_strncpy(qdi->info.driver, "AVF",
pj_ansi_strxcpy(qdi->info.driver, "AVF",
sizeof(qdi->info.driver));
qdi->info.dir = PJMEDIA_DIR_CAPTURE;
qdi->info.has_callback = PJ_FALSE;

View File

@ -475,7 +475,7 @@ static pj_status_t dshow_factory_refresh(pjmedia_vid_dev_factory *f)
CoTaskMemFree(wszDisplayName);
}
pj_ansi_strncpy(ddi->info.driver, "dshow",
pj_ansi_strxcpy(ddi->info.driver, "dshow",
sizeof(ddi->info.driver));
ddi->info.dir = PJMEDIA_DIR_CAPTURE;
ddi->info.has_callback = PJ_TRUE;
@ -504,9 +504,9 @@ static pj_status_t dshow_factory_refresh(pjmedia_vid_dev_factory *f)
#if HAS_VMR
ddi = &df->dev_info[df->dev_count++];
pj_bzero(ddi, sizeof(*ddi));
pj_ansi_strncpy(ddi->info.name, "Video Mixing Renderer",
pj_ansi_strxcpy(ddi->info.name, "Video Mixing Renderer",
sizeof(ddi->info.name));
pj_ansi_strncpy(ddi->info.driver, "dshow",
pj_ansi_strxcpy(ddi->info.driver, "dshow",
sizeof(ddi->info.driver));
ddi->info.driver[sizeof(ddi->info.driver)-1] = '\0';
ddi->info.dir = PJMEDIA_DIR_RENDER;

View File

@ -467,7 +467,7 @@ static pj_status_t ffmpeg_factory_refresh(pjmedia_vid_dev_factory *f)
info = &ff->dev_info[ff->dev_count++];
pj_bzero(info, sizeof(*info));
pj_ansi_strncpy(info->base.name, "default",
pj_ansi_strxcpy(info->base.name, "default",
sizeof(info->base.name));
pj_ansi_snprintf(info->base.driver, sizeof(info->base.driver),
"ffmpeg %s", p->name);

View File

@ -493,21 +493,21 @@ static pj_status_t sdl_factory_init(pjmedia_vid_dev_factory *f)
ddi = &sf->dev_info[0];
pj_bzero(ddi, sizeof(*ddi));
pj_ansi_strncpy(ddi->info.name, "SDL renderer",
pj_ansi_strxcpy(ddi->info.name, "SDL renderer",
sizeof(ddi->info.name));
ddi->info.fmt_cnt = PJ_ARRAY_SIZE(sdl_fmts);
#if PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL
ddi = &sf->dev_info[OPENGL_DEV_IDX];
pj_bzero(ddi, sizeof(*ddi));
pj_ansi_strncpy(ddi->info.name, "SDL openGL renderer",
pj_ansi_strxcpy(ddi->info.name, "SDL openGL renderer",
sizeof(ddi->info.name));
ddi->info.fmt_cnt = 1;
#endif /* PJMEDIA_VIDEO_DEV_SDL_HAS_OPENGL */
for (i = 0; i < sf->dev_count; i++) {
ddi = &sf->dev_info[i];
pj_ansi_strncpy(ddi->info.driver, "SDL",
pj_ansi_strxcpy(ddi->info.driver, "SDL",
sizeof(ddi->info.driver));
ddi->info.dir = PJMEDIA_DIR_RENDER;
ddi->info.has_callback = PJ_FALSE;

View File

@ -353,10 +353,10 @@ static pj_status_t v4l2_scan_devs(vid4lin_factory *f)
continue;
}
pj_ansi_strncpy(pdi->dev_name, dev_name, sizeof(pdi->dev_name));
pj_ansi_strncpy(pdi->info.name, (char*)pdi->v4l2_cap.card,
pj_ansi_strxcpy(pdi->dev_name, dev_name, sizeof(pdi->dev_name));
pj_ansi_strxcpy(pdi->info.name, (char*)pdi->v4l2_cap.card,
sizeof(pdi->info.name));
pj_ansi_strncpy(pdi->info.driver, DRIVER_NAME,
pj_ansi_strxcpy(pdi->info.driver, DRIVER_NAME,
sizeof(pdi->info.driver));
pdi->info.dir = PJMEDIA_DIR_CAPTURE;
pdi->info.has_callback = PJ_FALSE;
@ -616,7 +616,7 @@ static pj_status_t vid4lin_factory_create_stream(pjmedia_vid_dev_factory *f,
pj_memcpy(&stream->param, param, sizeof(*param));
stream->pool = pool;
pj_memcpy(&stream->vid_cb, cb, sizeof(*cb));
pj_ansi_strncpy(stream->name, vdi->info.name, sizeof(stream->name));
pj_ansi_strxcpy(stream->name, vdi->info.name, sizeof(stream->name));
stream->user_data = user_data;
stream->fd = INVALID_FD;

View File

@ -135,7 +135,7 @@ PJ_DEF(pj_status_t) pjmedia_aud_driver_init(unsigned drv_idx,
if (drv->name[0]=='\0') {
/* Set driver name */
pj_ansi_strncpy(drv->name, info.driver, sizeof(drv->name));
pj_ansi_strxcpy(drv->name, info.driver, sizeof(drv->name));
}
if (drv->play_dev_idx < 0 && info.output_count) {

View File

@ -106,7 +106,7 @@ PJ_DEF(pj_status_t) pjmedia_delay_buf_create( pj_pool_t *pool,
b = PJ_POOL_ZALLOC_T(pool, pjmedia_delay_buf);
pj_ansi_strncpy(b->obj_name, name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(b->obj_name, name, PJ_MAX_OBJ_NAME);
b->samples_per_frame = samples_per_frame;
b->channel_count = channel_count;

View File

@ -59,7 +59,7 @@ PJ_DEF(const pjmedia_snd_dev_info*) pjmedia_snd_get_dev_info(unsigned index)
return NULL;
pj_bzero(oi, sizeof(*oi));
pj_ansi_strncpy(oi->name, di.name, sizeof(oi->name));
pj_ansi_strxcpy(oi->name, di.name, sizeof(oi->name));
oi->input_count = di.input_count;
oi->output_count = di.output_count;
oi->default_samples_per_sec = di.default_samples_per_sec;

View File

@ -125,7 +125,7 @@ PJ_DEF(pj_status_t) pjmedia_tp_adapter_create( pjmedia_endpt *endpt,
pool = pjmedia_endpt_create_pool(endpt, name, 512, 512);
adapter = PJ_POOL_ZALLOC_T(pool, struct tp_adapter);
adapter->pool = pool;
pj_ansi_strncpy(adapter->base.name, pool->obj_name,
pj_ansi_strxcpy(adapter->base.name, pool->obj_name,
sizeof(adapter->base.name));
adapter->base.type = (pjmedia_transport_type)
(PJMEDIA_TRANSPORT_TYPE_USER + 1);

View File

@ -285,7 +285,8 @@ PJ_DEF(pj_status_t) pjmedia_ice_create3(pjmedia_endpt *endpt,
tp_ice->pool = pool;
tp_ice->options = options;
tp_ice->comp_cnt = comp_cnt;
pj_ansi_strcpy(tp_ice->base.name, pool->obj_name);
pj_ansi_strxcpy(tp_ice->base.name, pool->obj_name,
sizeof(tp_ice->base.name));
tp_ice->base.op = &transport_ice_op;
tp_ice->base.type = PJMEDIA_TRANSPORT_TYPE_ICE;
tp_ice->base.user_data = user_data;

View File

@ -255,7 +255,7 @@ static pj_status_t dtls_create(transport_srtp *srtp,
ds = PJ_POOL_ZALLOC_T(pool, dtls_srtp);
ds->pool = pool;
pj_ansi_strncpy(ds->base.name, pool->obj_name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(ds->base.name, pool->obj_name, PJ_MAX_OBJ_NAME);
ds->base.type = (pjmedia_transport_type)PJMEDIA_SRTP_KEYING_DTLS_SRTP;
ds->base.op = &dtls_op;
ds->base.user_data = srtp;

View File

@ -79,7 +79,7 @@ static pj_status_t sdes_create(transport_srtp *srtp,
pjmedia_transport *sdes;
sdes = PJ_POOL_ZALLOC_T(srtp->pool, pjmedia_transport);
pj_ansi_strncpy(sdes->name, srtp->pool->obj_name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(sdes->name, srtp->pool->obj_name, PJ_MAX_OBJ_NAME);
pj_memcpy(sdes->name, "sdes", 4);
sdes->type = (pjmedia_transport_type)PJMEDIA_SRTP_KEYING_SDES;
sdes->op = &sdes_op;

View File

@ -252,7 +252,7 @@ PJ_DEF(pj_status_t) pjmedia_vid_driver_init(unsigned drv_idx,
if (drv->name[0]=='\0') {
/* Set driver name */
pj_ansi_strncpy(drv->name, info.driver, sizeof(drv->name));
pj_ansi_strxcpy(drv->name, info.driver, sizeof(drv->name));
}
if (drv->rend_dev_idx < 0 && (info.dir & PJMEDIA_DIR_RENDER)) {

View File

@ -818,7 +818,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice,
pj_assert(i < PJ_ARRAY_SIZE(ice->tp_data) &&
ice->tp_data[i].transport_id == transport_id);
pj_ansi_strncpy(ice->tmp.txt, pj_sockaddr_print(&lcand->addr, address,
pj_ansi_strxcpy(ice->tmp.txt, pj_sockaddr_print(&lcand->addr, address,
sizeof(address), 2),
sizeof(ice->tmp.txt));
LOG4((ice->obj_name,

View File

@ -409,15 +409,15 @@ static void menu(void)
if (g.relay) {
pj_turn_sock_get_info(g.relay, &info);
pj_ansi_strncpy(client_state, pj_turn_state_name(info.state),
pj_ansi_strxcpy(client_state, pj_turn_state_name(info.state),
sizeof(client_state));
if (info.state >= PJ_TURN_STATE_READY)
pj_sockaddr_print(&info.relay_addr, relay_addr, sizeof(relay_addr), 3);
else
strcpy(relay_addr, "0.0.0.0:0");
pj_ansi_strxcpy(relay_addr, "0.0.0.0:0", sizeof(relay_addr));
} else {
pj_ansi_strncpy(client_state, "NULL", sizeof(client_state));
pj_ansi_strncpy(relay_addr, "0.0.0.0:0", sizeof(relay_addr));
pj_ansi_strxcpy(client_state, "NULL", sizeof(client_state));
pj_ansi_strxcpy(relay_addr, "0.0.0.0:0", sizeof(relay_addr));
}
pj_sockaddr_print(&g.peer[0].mapped_addr, peer0_addr, sizeof(peer0_addr), 3);
@ -476,7 +476,7 @@ static void console_main(void)
else
peer = &g.peer[1];
strcpy(input, "Hello from client");
pj_ansi_strxcpy(input, "Hello from client", sizeof(input));
status = pj_turn_sock_sendto(g.relay, (const pj_uint8_t*)input,
strlen(input)+1,
&peer->mapped_addr,

View File

@ -326,8 +326,9 @@ PJ_DEF(pj_status_t) pj_turn_allocation_create(pj_turn_transport *transport,
alloc->ch_table = pj_hash_create(pool, PEER_TABLE_SIZE);
/* Print info */
pj_ansi_strcpy(alloc->info,
pj_turn_tp_type_name(transport->listener->tp_type));
pj_ansi_strxcpy(alloc->info,
pj_turn_tp_type_name(transport->listener->tp_type),
sizeof(alloc->info));
alloc->info[3] = ':';
pj_sockaddr_print(src_addr, alloc->info+4, sizeof(alloc->info)-4, 3);

View File

@ -49,7 +49,7 @@ static struct cred_t
PJ_DEF(pj_status_t) pj_turn_auth_init(const char *realm)
{
PJ_ASSERT_RETURN(pj_ansi_strlen(realm) < MAX_REALM, PJ_ENAMETOOLONG);
pj_ansi_strcpy(g_realm, realm);
pj_ansi_strxcpy(g_realm, realm, sizeof(g_realm));
return PJ_SUCCESS;
}

View File

@ -98,7 +98,7 @@ PJ_DEF(pj_status_t) pj_turn_listener_create_tcp(pj_turn_srv *srv,
goto on_error;
/* Create info */
pj_ansi_strcpy(tcp_lis->base.info, "TCP:");
pj_ansi_strxcpy(tcp_lis->base.info, "TCP:", sizeof(tcp_lis->base.info));
pj_sockaddr_print(&tcp_lis->base.addr, tcp_lis->base.info+4,
sizeof(tcp_lis->base.info)-4, 3);

View File

@ -102,7 +102,7 @@ PJ_DEF(pj_status_t) pj_turn_listener_create_udp( pj_turn_srv *srv,
goto on_error;
/* Create info */
pj_ansi_strcpy(udp->base.info, "UDP:");
pj_ansi_strxcpy(udp->base.info, "UDP:", sizeof(udp->base.info));
pj_sockaddr_print(&udp->base.addr, udp->base.info+4,
sizeof(udp->base.info)-4, 3);

View File

@ -599,7 +599,7 @@ static pjsip_redirect_op call_on_redirected(pjsua_call_id call_id,
len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, target, uristr,
sizeof(uristr));
if (len < 1) {
pj_ansi_strcpy(uristr, "--URI too long--");
pj_ansi_strxcpy(uristr, "--URI too long--", sizeof(uristr));
}
PJ_LOG(3,(THIS_FILE, "Call %d is being redirected to %.*s. "

View File

@ -467,7 +467,7 @@ static void get_media_port(pj_cli_dyn_choice_param *param)
for (j=0; j<info.listener_cnt; ++j) {
char s[10];
pj_ansi_snprintf(s, sizeof(s), "#%d ", info.listeners[j]);
pj_ansi_strcat(txlist, s);
pj_ansi_strxcat(txlist, s, sizeof(txlist));
}
len = pj_ansi_snprintf(desc,
@ -1255,7 +1255,7 @@ static pj_status_t cmd_media_list(pj_cli_cmd_val *cval)
for (j=0; j<info.listener_cnt; ++j) {
char s[10];
pj_ansi_snprintf(s, sizeof(s), "#%d ", info.listeners[j]);
pj_ansi_strcat(txlist, s);
pj_ansi_strxcat(txlist, s, sizeof(txlist));
}
pj_ansi_snprintf(out_str,
sizeof(out_str),
@ -2524,14 +2524,14 @@ static pj_status_t cmd_vid_conf_list()
pj_ansi_snprintf(str_info, sizeof(str_info), "%d%s",
info.listeners[j],
(j==info.listener_cnt-1)?"":",");
pj_ansi_strcat(li_list, str_info);
pj_ansi_strxcat(li_list, str_info, sizeof(li_list));
}
tr_list[0] = '\0';
for (j=0; j<info.transmitter_cnt; ++j) {
char str_info[10];
pj_ansi_snprintf(str_info, sizeof(str_info), "%d%s", info.transmitters[j],
(j==info.transmitter_cnt-1)?"":",");
pj_ansi_strcat(tr_list, str_info);
pj_ansi_strxcat(tr_list, str_info, sizeof(tr_list));
}
pjmedia_fourcc_name(info.format.id, s);
s[4] = ' ';

View File

@ -302,8 +302,8 @@ void vid_print_dev(int id, const pjmedia_vid_dev_info *vdi, const char *title)
st_len += (tmp_len + 2);
if (*capnames)
strcat(capnames, ", ");
strcat(capnames, capname);
pj_ansi_strxcat(capnames, ", ", sizeof(capnames));
pj_ansi_strxcat(capnames, capname, sizeof(capnames));
}
}
}
@ -322,8 +322,8 @@ void vid_print_dev(int id, const pjmedia_vid_dev_info *vdi, const char *title)
st_len += (tmp_len + 2);
if (*formats)
strcat(formats, ", ");
strcat(formats, vfi->name);
pj_ansi_strxcat(formats, ", ", sizeof(formats));
pj_ansi_strxcat(formats, vfi->name, sizeof(formats));
}
}

View File

@ -639,7 +639,7 @@ static void vid_handle_menu(char *menuin)
pj_ansi_snprintf(str_info, sizeof(str_info), "%d%s",
info.listeners[j],
(j==info.listener_cnt-1)?"":",");
pj_ansi_strcat(li_list, str_info);
pj_ansi_strxcat(li_list, str_info, sizeof(li_list));
}
tr_list[0] = '\0';
for (j=0; j<info.transmitter_cnt; ++j) {
@ -647,7 +647,7 @@ static void vid_handle_menu(char *menuin)
pj_ansi_snprintf(str_info, sizeof(str_info), "%d%s",
info.transmitters[j],
(j==info.transmitter_cnt-1)?"":",");
pj_ansi_strcat(tr_list, str_info);
pj_ansi_strxcat(tr_list, str_info, sizeof(tr_list));
}
pjmedia_fourcc_name(info.format.id, s);
s[4] = ' ';
@ -1613,7 +1613,7 @@ static void ui_conf_list()
for (j=0; j<info.listener_cnt; ++j) {
char s[10];
pj_ansi_snprintf(s, sizeof(s), "#%d ", info.listeners[j]);
pj_ansi_strcat(txlist, s);
pj_ansi_strxcat(txlist, s, sizeof(txlist));
}
printf("Port #%02d[%2dKHz/%dms/%d] %20.*s transmitting to: %s\n",
info.slot_id,

View File

@ -90,7 +90,8 @@ static gui_menu root_menu = {
#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0
PJ_INLINE(char *) add_path(const char *path, const char *fname)
{
pj_ansi_safe_strcpycat(fpath, path, fname, PATH_LENGTH);
pj_ansi_strxcpy(fpath, path, PATH_LENGTH);
pj_ansi_strxcat(fpath, fname, PATH_LENGTH);
return fpath;
}
#else
@ -130,9 +131,11 @@ static void systest_perror(const char *title, pj_status_t status)
if (status != PJ_SUCCESS)
pj_strerror(status, errmsg, sizeof(errmsg));
else
errmsg[0] = '\0';
pj_ansi_strxcpy(errmsg, "No error", sizeof(errmsg));
pj_ansi_safe_strcpycat(themsg, title, errmsg, sizeof(themsg));
pj_ansi_strxcpy(themsg, title, sizeof(themsg));
pj_ansi_strxcat(themsg, ": ", sizeof(themsg));
pj_ansi_strxcat(themsg, errmsg, sizeof(themsg));
gui_msgbox("Error", themsg, WITH_OK);
}
@ -147,7 +150,7 @@ test_item_t *systest_alloc_test_item(const char *title)
ti = &test_items[test_item_count++];
pj_bzero(ti, sizeof(*ti));
pj_ansi_strncpy(ti->title, title, sizeof(ti->title));
pj_ansi_strxcpy(ti->title, title, sizeof(ti->title));
return ti;
}
@ -249,14 +252,14 @@ on_return:
if (status != PJ_SUCCESS) {
systest_perror("Sorry we encounter error when initializing "
"the tone generator: ", status);
"the tone generator", status);
ti->success = PJ_FALSE;
pj_strerror(status, ti->reason, sizeof(ti->reason));
} else {
key = gui_msgbox(title, "Is the audio okay?", WITH_YESNO);
ti->success = (key == KEY_YES);
if (!ti->success)
pj_ansi_strcpy(ti->reason, USER_ERROR);
pj_ansi_strxcpy(ti->reason, USER_ERROR, sizeof(ti->reason));
}
return;
}
@ -339,7 +342,7 @@ on_return:
key = gui_msgbox(title, "Is the audio okay?", WITH_YESNO);
ti->success = (key == KEY_YES);
if (!ti->success)
pj_ansi_strcpy(ti->reason, USER_ERROR);
pj_ansi_strxcpy(ti->reason, USER_ERROR, sizeof(ti->reason));
}
return;
}
@ -445,7 +448,7 @@ on_return:
pj_pool_release(pool);
if (status != PJ_SUCCESS) {
systest_perror("Sorry we encountered an error: ", status);
systest_perror("Sorry we encountered an error", status);
ti->success = PJ_FALSE;
pj_strerror(status, ti->reason, sizeof(ti->reason));
} else {
@ -459,7 +462,7 @@ on_return:
"or playback problem.",
WAV_REC_OUT_PATH);
gui_msgbox(title, textbuf, WITH_OK);
pj_ansi_strcpy(ti->reason, USER_ERROR);
pj_ansi_strxcpy(ti->reason, USER_ERROR, sizeof(ti->reason));
}
}
}
@ -546,7 +549,8 @@ static void systest_audio_test(void)
pjsua_set_snd_dev(systest.rec_id, systest.play_id);
/* Analyze the result! */
strcpy(textbuf, "Here are the audio statistics:\r\n");
pj_ansi_strxcpy(textbuf, "Here are the audio statistics:\r\n",
sizeof(textbuf));
textbufpos = strlen(textbuf);
if (result.rec.frame_cnt==0) {
@ -637,7 +641,7 @@ static void systest_audio_test(void)
}
ti->success = PJ_TRUE;
pj_ansi_strncpy(ti->reason, textbuf, sizeof(ti->reason));
pj_ansi_strxcpy(ti->reason, textbuf, sizeof(ti->reason));
}
@ -886,13 +890,13 @@ on_return:
pjsua_recorder_destroy(rec_id);
if (status != PJ_SUCCESS) {
systest_perror("Sorry we encountered an error: ", status);
systest_perror("Sorry we encountered an error", status);
ti->success = PJ_FALSE;
pj_strerror(status, ti->reason, sizeof(ti->reason));
} else if (key != KEY_YES) {
ti->success = PJ_FALSE;
if (!ti->success) {
pj_ansi_strcpy(ti->reason, USER_ERROR);
pj_ansi_strxcpy(ti->reason, USER_ERROR, sizeof(ti->reason));
}
} else {
char msg[200];
@ -917,7 +921,7 @@ on_return:
key = gui_msgbox(title, msg, WITH_OK);
ti->success = PJ_TRUE;
pj_ansi_strncpy(ti->reason, msg, sizeof(ti->reason));
pj_ansi_strxcpy(ti->reason, msg, sizeof(ti->reason));
}
}
@ -1042,13 +1046,13 @@ on_return:
if (status != PJ_SUCCESS) {
systest_perror("Sorry we encountered an error: ", status);
systest_perror("Sorry we encountered an error", status);
ti->success = PJ_FALSE;
pj_strerror(status, ti->reason, sizeof(ti->reason));
} else if (key == KEY_YES) {
ti->success = PJ_FALSE;
if (!ti->success) {
pj_ansi_strcpy(ti->reason, USER_ERROR);
pj_ansi_strxcpy(ti->reason, USER_ERROR, sizeof(ti->reason));
}
} else {
char msg[200];
@ -1056,7 +1060,7 @@ on_return:
pj_ansi_snprintf(msg, sizeof(msg), "Test succeeded.\r\n");
ti->success = PJ_TRUE;
pj_ansi_strncpy(ti->reason, msg, sizeof(ti->reason));
pj_ansi_strxcpy(ti->reason, msg, sizeof(ti->reason));
}
}
@ -1084,7 +1088,7 @@ static void systest_list_audio_devs()
key = gui_msgbox(title,
"No audio devices are found", WITH_OK);
ti->success = PJ_FALSE;
pj_ansi_strcpy(ti->reason, "No device found");
pj_ansi_strxcpy(ti->reason, "No device found", sizeof(ti->reason));
return;
}
@ -1097,7 +1101,7 @@ static void systest_list_audio_devs()
status = pjmedia_aud_dev_get_info(i, &info);
if (status != PJ_SUCCESS) {
systest_perror("Error retrieving device info: ", status);
systest_perror("Error retrieving device info", status);
ti->success = PJ_FALSE;
pj_strerror(status, ti->reason, sizeof(ti->reason));
return;
@ -1201,7 +1205,7 @@ static void systest_display_settings(void)
len = strlen(textbuf);
ti->success = PJ_TRUE;
pj_ansi_strncpy(ti->reason, textbuf, sizeof(ti->reason));
pj_ansi_strxcpy(ti->reason, textbuf, sizeof(ti->reason));
key = gui_msgbox(title, textbuf, WITH_OK);
PJ_UNUSED_ARG(key); /* Warning about unused var */
}
@ -1215,7 +1219,7 @@ int systest_init(void)
status = pjsua_create();
if (status != PJ_SUCCESS) {
systest_perror("Sorry we've had error in pjsua_create(): ", status);
systest_perror("Sorry we've had error in pjsua_create()", status);
return status;
}
@ -1245,14 +1249,14 @@ int systest_init(void)
status = pjsua_init(&systest.ua_cfg, &log_cfg, &systest.media_cfg);
if (status != PJ_SUCCESS) {
pjsua_destroy();
systest_perror("Sorry we've had error in pjsua_init(): ", status);
systest_perror("Sorry we've had error in pjsua_init()", status);
return status;
}
status = pjsua_start();
if (status != PJ_SUCCESS) {
pjsua_destroy();
systest_perror("Sorry we've had error in pjsua_start(): ", status);
systest_perror("Sorry we've had error in pjsua_start()", status);
return status;
}

View File

@ -3863,7 +3863,7 @@ static PyObject *py_pj_parse_simple_sip(PyObject *pSelf, PyObject *pArgs)
return NULL;
}
pj_ansi_strncpy(tmp, arg_uri, sizeof(tmp));
pj_ansi_strxcpy(tmp, arg_uri, sizeof(tmp));
pool = pjsua_pool_create("py_pj_parse_simple_sip", 512, 512);
uri = pjsip_parse_uri(pool, tmp, strlen(tmp), 0);

View File

@ -77,10 +77,8 @@ static const char *decode_caps(unsigned caps)
const char *capname;
capname = pjmedia_aud_dev_cap_name((pjmedia_aud_dev_cap)(1 << i),
NULL);
if (strlen(text) + strlen(capname) + 2 < sizeof(text)) {
strcat(text, capname);
strcat(text, " ");
}
pj_ansi_strxcat(text, capname, sizeof(text));
pj_ansi_strxcat(text, " ", sizeof(text));
}
}
@ -124,30 +122,31 @@ static void show_dev_info(unsigned index)
switch (info.ext_fmt[i].id) {
case PJMEDIA_FORMAT_L16:
strcat(formats, "L16/");
pj_ansi_strxcat(formats, "L16/", sizeof(formats));
break;
case PJMEDIA_FORMAT_PCMA:
strcat(formats, "PCMA/");
pj_ansi_strxcat(formats, "PCMA/", sizeof(formats));
break;
case PJMEDIA_FORMAT_PCMU:
strcat(formats, "PCMU/");
pj_ansi_strxcat(formats, "PCMU/", sizeof(formats));
break;
case PJMEDIA_FORMAT_AMR:
strcat(formats, "AMR/");
pj_ansi_strxcat(formats, "AMR/", sizeof(formats));
break;
case PJMEDIA_FORMAT_G729:
strcat(formats, "G729/");
pj_ansi_strxcat(formats, "G729/", sizeof(formats));
break;
case PJMEDIA_FORMAT_ILBC:
strcat(formats, "ILBC/");
pj_ansi_strxcat(formats, "ILBC/", sizeof(formats));
break;
default:
strcat(formats, "unknown/");
pj_ansi_strxcat(formats, "unknown/", sizeof(formats));
break;
}
sprintf(bitrate, "%u", info.ext_fmt[i].det.aud.avg_bps);
strcat(formats, bitrate);
strcat(formats, " ");
pj_ansi_snprintf(bitrate, sizeof(bitrate), "%u",
info.ext_fmt[i].det.aud.avg_bps);
pj_ansi_strxcat(formats, bitrate, sizeof(formats));
pj_ansi_strxcat(formats, " ", sizeof(formats));
}
}
PJ_LOG(3, (THIS_FILE, H": %s", "Extended formats", formats));

View File

@ -492,8 +492,9 @@ static void conf_list(pjmedia_conf *conf, int detail)
txlist[0] = '\0';
for (j=0; j<port_info->listener_cnt; ++j) {
char s[10];
pj_ansi_sprintf(s, "#%d ", port_info->listener_slots[j]);
pj_ansi_strcat(txlist, s);
pj_ansi_snprintf(s, sizeof(s), "#%d ",
port_info->listener_slots[j]);
pj_ansi_strxcat(txlist, s, sizeof(txlist));
}

View File

@ -778,16 +778,18 @@ static void icedemo_input_remote(void)
goto on_error;
}
strcpy(comp0_addr, ip);
pj_ansi_strxcpy(comp0_addr, ip, sizeof(comp0_addr));
}
break;
case 'a':
{
char *attr = strtok(line+2, ": \t\r\n");
if (strcmp(attr, "ice-ufrag")==0) {
strcpy(icedemo.rem.ufrag, attr+strlen(attr)+1);
pj_ansi_strxcpy(icedemo.rem.ufrag, attr+strlen(attr)+1,
sizeof(icedemo.rem.ufrag));
} else if (strcmp(attr, "ice-pwd")==0) {
strcpy(icedemo.rem.pwd, attr+strlen(attr)+1);
pj_ansi_strxcpy(icedemo.rem.pwd, attr+strlen(attr)+1,
sizeof(icedemo.rem.pwd));
} else if (strcmp(attr, "rtcp")==0) {
char *val = attr+strlen(attr)+1;
int af, cnt;

View File

@ -216,23 +216,29 @@ static void write_log(struct log_entry *entry, pj_bool_t to_stdout)
}
if (entry->jb_state) {
sprintf(s_jbprefetch, "%d", entry->jb_state->prefetch);
sprintf(s_jbsize, "%d", entry->jb_state->size);
sprintf(s_jbdiscard, "%d", entry->jb_state->discard);
sprintf(s_jbempty, "%d", entry->jb_state->empty);
pj_ansi_snprintf(s_jbprefetch, sizeof(s_jbprefetch),
"%d", entry->jb_state->prefetch);
pj_ansi_snprintf(s_jbsize, sizeof(s_jbsize),
"%d", entry->jb_state->size);
pj_ansi_snprintf(s_jbdiscard, sizeof(s_jbdiscard),
"%d", entry->jb_state->discard);
pj_ansi_snprintf(s_jbempty, sizeof(s_jbempty),
"%d", entry->jb_state->empty);
} else {
strcpy(s_jbprefetch, "");
strcpy(s_jbsize, "");
strcpy(s_jbdiscard, "");
strcpy(s_jbempty, "");
s_jbprefetch[0] = '\0';
s_jbsize[0] = '\0';
s_jbdiscard[0] = '\0';
s_jbempty[0] = '\0';
}
if (entry->stat) {
sprintf(s_rxpkt, "%d", entry->stat->rx.pkt);
sprintf(s_losspkt, "%d", entry->stat->rx.loss);
pj_ansi_snprintf(s_rxpkt, sizeof(s_rxpkt),
"%d", entry->stat->rx.pkt);
pj_ansi_snprintf(s_losspkt, sizeof(s_losspkt),
"%d", entry->stat->rx.loss);
} else {
strcpy(s_rxpkt, "");
strcpy(s_losspkt, "");
s_rxpkt[0] = '\0';
s_losspkt[0] = '\0';
}
if (entry->log == NULL)
@ -694,7 +700,8 @@ static void tx_tick(const pj_time_val *t)
entry.log = log_msg;
if (jstate.discard > last_discard)
strcat(log_msg, "** Note: packet was discarded by jitter buffer **");
pj_ansi_strxcat(log_msg, "** Note: packet was discarded by jitter buffer **",
sizeof(log_msg));
strm->state.tx.cur_lost_burst = 0;
}
@ -806,9 +813,10 @@ static void rx_tick(const pj_time_val *t)
entry.log = msg;
if (jstate.empty > last_empty)
strcat(msg, "** JBUF was empty **");
pj_ansi_strxcat(msg, "** JBUF was empty **", sizeof(msg));
if (!has_frame)
strcat(msg, "** NULL frame was returned **");
pj_ansi_strxcat(msg, "** NULL frame was returned **",
sizeof(msg));
write_log(&entry, PJ_TRUE);
@ -982,14 +990,14 @@ static int init_options(int argc, char *argv[])
if (long_options[c].has_arg) {
char cmd[10];
pj_ansi_snprintf(cmd, sizeof(cmd), "%c:", long_options[c].val);
pj_ansi_strcat(format, cmd);
pj_ansi_strxcat(format, cmd, sizeof(format));
}
}
for (c=0; c<(int)PJ_ARRAY_SIZE(long_options)-1; ++c) {
if (long_options[c].has_arg == 0) {
char cmd[10];
pj_ansi_snprintf(cmd, sizeof(cmd), "%c", long_options[c].val);
pj_ansi_strcat(format, cmd);
pj_ansi_strxcat(format, cmd, sizeof(format));
}
}

View File

@ -808,7 +808,7 @@ static pj_status_t init_sip()
}
app.local_uri.ptr = pj_pool_alloc(app.pool, 128);
app.local_uri.slen = pj_ansi_sprintf(app.local_uri.ptr,
app.local_uri.slen = pj_ansi_snprintf(app.local_uri.ptr, 128,
"<sip:pjsip-perf@%.*s:%d;transport=%s>",
(int)app.local_addr.slen,
app.local_addr.ptr,
@ -1103,7 +1103,7 @@ static pj_status_t verify_sip_url(const char *c_url)
if (!pool) return PJ_ENOMEM;
url = pj_pool_alloc(pool, len+1);
pj_ansi_strcpy(url, c_url);
pj_ansi_strxcpy(url, c_url, len+1);
url[len] = '\0';
p = pjsip_parse_uri(pool, url, len, 0);
@ -1556,16 +1556,16 @@ static int client_thread(void *arg)
}
static const char *good_number(char *buf, pj_int32_t val)
static const char *good_number(char *buf, unsigned buf_size, pj_int32_t val)
{
if (val < 1000) {
pj_ansi_sprintf(buf, "%d", val);
pj_ansi_snprintf(buf, buf_size, "%d", val);
} else if (val < 1000000) {
pj_ansi_sprintf(buf, "%d.%dK",
pj_ansi_snprintf(buf, buf_size, "%d.%dK",
val / 1000,
(val % 1000) / 100);
} else {
pj_ansi_sprintf(buf, "%d.%02dM",
pj_ansi_snprintf(buf, buf_size, "%d.%02dM",
val / 1000000,
(val % 1000000) / 10000);
}
@ -1616,9 +1616,12 @@ static int server_thread(void *arg)
stateful = app.server.cur_state.stateful_cnt - app.server.prev_state.stateful_cnt;
call = app.server.cur_state.call_cnt - app.server.prev_state.call_cnt;
good_number(str_stateless, app.server.cur_state.stateless_cnt);
good_number(str_stateful, app.server.cur_state.stateful_cnt);
good_number(str_call, app.server.cur_state.call_cnt);
good_number(str_stateless, sizeof(str_stateless),
app.server.cur_state.stateless_cnt);
good_number(str_stateful, sizeof(str_stateful),
app.server.cur_state.stateful_cnt);
good_number(str_call, sizeof(str_call),
app.server.cur_state.call_cnt);
printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s) \r",
str_stateless, stateless*1000/msec,
@ -1695,13 +1698,15 @@ int main(int argc, char *argv[])
/* Get the job name */
if (app.client.method.id == PJSIP_INVITE_METHOD) {
pj_ansi_strcpy(test_type, "INVITE calls");
pj_ansi_strxcpy(test_type, "INVITE calls", sizeof(test_type));
} else if (app.client.stateless) {
pj_ansi_sprintf(test_type, "stateless %.*s requests",
pj_ansi_snprintf(test_type, sizeof(test_type),
"stateless %.*s requests",
(int)app.client.method.name.slen,
app.client.method.name.ptr);
} else {
pj_ansi_sprintf(test_type, "stateful %.*s requests",
pj_ansi_snprintf(test_type, sizeof(test_type),
"stateful %.*s requests",
(int)app.client.method.name.slen,
app.client.method.name.ptr);
}
@ -1765,7 +1770,8 @@ int main(int argc, char *argv[])
write_report(report);
/* Print detailed response code received */
pj_ansi_sprintf(report, "\nDetailed responses received:");
pj_ansi_snprintf(report, sizeof(report),
"\nDetailed responses received:");
write_report(report);
for (i=0; i<PJ_ARRAY_SIZE(app.client.response_codes); ++i) {
@ -1791,7 +1797,8 @@ int main(int argc, char *argv[])
write_report(report);
pj_ansi_sprintf(report, "Maximum outstanding job: %d",
pj_ansi_snprintf(report, sizeof(report),
"Maximum outstanding job: %d",
app.client.stat_max_window);
write_report(report);

View File

@ -54,7 +54,8 @@ static void print_call(int call_index)
PJ_TIME_VAL_SUB(now, call->connect_time);
sprintf(duration, " [duration: %02ld:%02ld:%02ld.%03ld]",
pj_ansi_snprintf(duration, sizeof(duration),
" [duration: %02ld:%02ld:%02ld.%03ld]",
now.sec / 3600,
(now.sec % 3600) / 60,
(now.sec % 60),
@ -77,7 +78,7 @@ static void print_call(int call_index)
/* Call identification */
len = pjsip_hdr_print_on(dlg->remote.info, userinfo, sizeof(userinfo));
if (len < 0)
pj_ansi_strcpy(userinfo, "<--uri too long-->");
pj_ansi_strxcpy(userinfo, "<--uri too long-->", sizeof(userinfo));
else
userinfo[len] = '\0';
@ -100,7 +101,9 @@ static void print_call(int call_index)
if (call->response_time.sec) {
t = call->response_time;
PJ_TIME_VAL_SUB(t, call->start_time);
sprintf(pdd, "got 1st response in %ld ms", PJ_TIME_VAL_MSEC(t));
pj_ansi_snprintf(pdd, sizeof(pdd),
"got 1st response in %ld ms",
PJ_TIME_VAL_MSEC(t));
} else {
pdd[0] = '\0';
}
@ -108,7 +111,8 @@ static void print_call(int call_index)
if (call->connect_time.sec) {
t = call->connect_time;
PJ_TIME_VAL_SUB(t, call->start_time);
sprintf(connectdelay, ", connected after: %ld ms",
pj_ansi_snprintf(connectdelay, sizeof(connectdelay),
", connected after: %ld ms",
PJ_TIME_VAL_MSEC(t));
} else {
connectdelay[0] = '\0';
@ -129,11 +133,12 @@ static void print_call(int call_index)
good_number(ipbps, (audio->bytes_per_frame+32) * audio->clock_rate / audio->samples_per_frame)));
if (audio->rtcp.stat.rx.update_cnt == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, audio->rtcp.stat.rx.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -173,11 +178,12 @@ static void print_call(int call_index)
if (audio->rtcp.stat.tx.update_cnt == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, audio->rtcp.stat.tx.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,

View File

@ -983,11 +983,12 @@ static void print_stream_stat(pjmedia_stream *stream,
codec_param->info.frm_ptime)));
if (stat.rx.update_cnt == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, stat.rx.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -1028,11 +1029,12 @@ static void print_stream_stat(pjmedia_stream *stream,
if (stat.tx.update_cnt == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, stat.tx.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -1137,11 +1139,12 @@ static void print_stream_stat(pjmedia_stream *stream,
sprintf(toh, "(report not available)");
if (xr_stat.rx.stat_sum.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.rx.stat_sum.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -1200,11 +1203,12 @@ static void print_stream_stat(pjmedia_stream *stream,
sprintf(toh, "(report not available)");
if (xr_stat.tx.stat_sum.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.tx.stat_sum.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -1268,11 +1272,12 @@ static void print_stream_stat(pjmedia_stream *stream,
sprintf(jbr, "%d", xr_stat.rx.voip_mtc.rx_config & 0x0F);
if (xr_stat.rx.voip_mtc.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.rx.voip_mtc.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -1355,11 +1360,12 @@ static void print_stream_stat(pjmedia_stream *stream,
sprintf(jbr, "%d", xr_stat.tx.voip_mtc.rx_config & 0x0F);
if (xr_stat.tx.voip_mtc.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.tx.voip_mtc.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,

View File

@ -41,7 +41,7 @@ const char* find_gcc(const char *gcc_exe)
return NULL;
}
pj_ansi_strncpy(spath, p, sizeof(spath));
pj_ansi_strxcpy(spath, p, sizeof(spath));
p = strtok(spath, ";");
while (p) {
int len;

View File

@ -292,7 +292,7 @@ void MainWin::call()
char uri[256];
pjsua_call_setting call_setting;
pj_ansi_strncpy(uri, dst.toUtf8().data(), sizeof(uri));
pj_ansi_strxcpy(uri, dst.toUtf8().data(), sizeof(uri));
pj_str_t uri2 = pj_str((char*)uri);
pj_assert(currentCall_ == -1);

View File

@ -3282,7 +3282,8 @@ PJ_DEF(pj_status_t) pjsip_inv_process_redirect( pjsip_inv_session *inv,
len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,
dlg->remote.info->uri, tmp, TMP_LEN);
if (len < 1) {
pj_ansi_strcpy(tmp, "<-error: uri too long->");
pj_ansi_strxcpy(tmp, "<-error: uri too long->",
sizeof(tmp));
len = (int)pj_ansi_strlen(tmp);
}
pj_strdup2_with_null(dlg->pool, &dlg->remote.info_str, tmp);

View File

@ -347,7 +347,7 @@ static void timer_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
(inv->timer->refresher == TR_UAS && inv->timer->role == PJSIP_ROLE_UAS);
entry_id = entry->id;
pj_ansi_strncpy(obj_name, inv->pool->obj_name, PJ_MAX_OBJ_NAME);
pj_ansi_strxcpy(obj_name, inv->pool->obj_name, PJ_MAX_OBJ_NAME);
/* Do action based on role(refresher or refreshee).
* As refresher:

View File

@ -408,8 +408,9 @@ pj_status_t create_uas_dialog( pjsip_user_agent *ua,
len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,
dlg->local.info->uri, tmp.ptr, TMP_LEN);
if (len < 1) {
pj_ansi_strcpy(tmp.ptr, "<-error: uri too long->");
tmp.slen = pj_ansi_strlen(tmp.ptr);
tmp.slen=pj_ansi_strxcpy(tmp.ptr, "<-error: uri too long->", TMP_LEN);
if (tmp.slen < 0)
tmp.slen = pj_ansi_strlen(tmp.ptr);
} else
tmp.slen = len;
@ -459,8 +460,9 @@ pj_status_t create_uas_dialog( pjsip_user_agent *ua,
len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,
dlg->remote.info->uri, tmp.ptr, TMP_LEN);
if (len < 1) {
pj_ansi_strcpy(tmp.ptr, "<-error: uri too long->");
tmp.slen = pj_ansi_strlen(tmp.ptr);
tmp.slen=pj_ansi_strxcpy(tmp.ptr, "<-error: uri too long->", TMP_LEN);
if (tmp.slen<0)
tmp.slen = pj_ansi_strlen(tmp.ptr);
} else
tmp.slen = len;

View File

@ -1269,7 +1269,7 @@ PJ_DEF(void) pjsip_endpt_log_error( pjsip_endpoint *endpt,
if (len < (int)sizeof(newformat)-30) {
pj_str_t errstr;
pj_ansi_strcpy(newformat, format);
pj_ansi_strxcpy(newformat, format, sizeof(newformat));
pj_ansi_snprintf(newformat+len, sizeof(newformat)-len-1,
": [err %d] ", error_code);
len += pj_ansi_strlen(newformat+len);

View File

@ -329,7 +329,8 @@ PJ_DEF(pj_status_t) pjsip_transport_register_type( unsigned tp_flag,
}
transport_names[i].port = (pj_uint16_t)def_port;
pj_ansi_strcpy(transport_names[i].name_buf, tp_name);
pj_ansi_strxcpy(transport_names[i].name_buf, tp_name,
sizeof(transport_names[i].name_buf));
transport_names[i].name = pj_str(transport_names[i].name_buf);
transport_names[i].flag = tp_flag;
@ -754,7 +755,7 @@ PJ_DEF(char*) pjsip_rx_data_get_info(pjsip_rx_data *rdata)
if (rdata->msg_info.info)
return rdata->msg_info.info;
pj_ansi_strcpy(obj_name, "rdata");
pj_ansi_strxcpy(obj_name, "rdata", sizeof(obj_name));
pj_ansi_snprintf(obj_name+5, sizeof(obj_name)-5, "%p", rdata);
rdata->msg_info.info = get_msg_info(rdata->tp_info.pool, obj_name,

View File

@ -95,9 +95,11 @@ static struct recv_list *create_incoming_packet( struct loop_transport *loop,
/* "Source address" info. */
pkt->rdata.pkt_info.src_addr_len = sizeof(pj_sockaddr_in);
if (loop->base.key.type == PJSIP_TRANSPORT_LOOP) {
pj_ansi_strcpy(pkt->rdata.pkt_info.src_name, ADDR_LOOP);
pj_ansi_strxcpy(pkt->rdata.pkt_info.src_name, ADDR_LOOP,
sizeof(pkt->rdata.pkt_info.src_name));
} else {
pj_ansi_strcpy(pkt->rdata.pkt_info.src_name, ADDR_LOOP_DGRAM);
pj_ansi_strxcpy(pkt->rdata.pkt_info.src_name, ADDR_LOOP_DGRAM,
sizeof(pkt->rdata.pkt_info.src_name));
}
pkt->rdata.pkt_info.src_port = loop->base.local_name.port;

View File

@ -399,9 +399,11 @@ PJ_DEF(pj_status_t) pjsip_tcp_transport_start3(
pj_memcpy(&listener->sockopt_params, &cfg->sockopt_params,
sizeof(cfg->sockopt_params));
pj_ansi_strcpy(listener->factory.obj_name, "tcptp");
pj_ansi_strxcpy(listener->factory.obj_name, "tcptp",
sizeof(listener->factory.obj_name));
if (listener->factory.type==PJSIP_TRANSPORT_TCP6)
pj_ansi_strcat(listener->factory.obj_name, "6");
pj_ansi_strxcat(listener->factory.obj_name, "6",
sizeof(listener->factory.obj_name));
status = pj_lock_create_recursive_mutex(pool, listener->factory.obj_name,
&listener->factory.lock);

View File

@ -574,9 +574,11 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_start2( pjsip_endpoint *endpt,
pjsip_transport_get_flag_from_type(listener->factory.type);
listener->endpt = endpt;
pj_ansi_strcpy(listener->factory.obj_name, "tlstp");
pj_ansi_strxcpy(listener->factory.obj_name, "tlstp",
sizeof(listener->factory.obj_name));
if (is_ipv6)
pj_ansi_strcat(listener->factory.obj_name, "6");
pj_ansi_strxcat(listener->factory.obj_name, "6",
sizeof(listener->factory.obj_name));
if (opt)
pjsip_tls_setting_copy(pool, &listener->tls_setting, opt);

View File

@ -970,7 +970,7 @@ static void print_dialog( const char *title,
len = pjsip_hdr_print_on(dlg->remote.info, userinfo, sizeof(userinfo));
if (len < 0)
pj_ansi_strcpy(userinfo, "<--uri too long-->");
pj_ansi_strxcpy(userinfo, "<--uri too long-->", sizeof(userinfo));
else
userinfo[len] = '\0';
@ -980,7 +980,7 @@ static void print_dialog( const char *title,
"est"),
userinfo);
if (len < 1 || len >= (int)size) {
pj_ansi_strcpy(buf, "<--uri too long-->");
pj_ansi_strxcpy(buf, "<--uri too long-->", size);
} else
buf[len] = '\0';
}

View File

@ -2556,7 +2556,7 @@ PJ_DEF(pj_status_t) pjsua_transport_create( pjsip_transport_type_e type,
if (status != PJ_SUCCESS)
goto on_return;
pj_ansi_strncpy(hostbuf, addr_string(&pub_addr), sizeof(hostbuf));
pj_ansi_strxcpy(hostbuf, addr_string(&pub_addr), sizeof(hostbuf));
addr_name.host = pj_str(hostbuf);
addr_name.port = pj_sockaddr_get_port(&pub_addr);
@ -3306,7 +3306,7 @@ PJ_DEF(pj_status_t) pjsua_verify_url(const char *c_url)
if (!pool) return PJ_ENOMEM;
url = (char*) pj_pool_alloc(pool, len+1);
pj_ansi_strcpy(url, c_url);
pj_ansi_strxcpy(url, c_url, len+1);
p = pjsip_parse_uri(pool, url, len, 0);
@ -3330,7 +3330,7 @@ PJ_DEF(pj_status_t) pjsua_verify_sip_url(const char *c_url)
if (!pool) return PJ_ENOMEM;
url = (char*) pj_pool_alloc(pool, len+1);
pj_ansi_strcpy(url, c_url);
pj_ansi_strxcpy(url, c_url, len+1);
p = pjsip_parse_uri(pool, url, len, 0);
if (!p || (pj_stricmp2(pjsip_uri_get_scheme(p), "sip") != 0 &&
@ -3758,7 +3758,7 @@ static pj_status_t handle_ip_change_on_acc()
if (pj_ansi_strlen(acc_id) + pj_ansi_strlen(tmp_buf) <
sizeof(acc_id))
{
pj_ansi_strcat(acc_id, tmp_buf);
pj_ansi_strxcat(acc_id, tmp_buf, sizeof(acc_id));
}
shut_acc_ids[shut_acc_cnt++] = j;

View File

@ -47,11 +47,12 @@ static unsigned dump_media_stat(const char *indent,
int len;
if (stat->rx.update_cnt == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, stat->rx.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -134,11 +135,12 @@ static unsigned dump_media_stat(const char *indent,
p += len;
if (stat->tx.update_cnt == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, stat->tx.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -440,11 +442,11 @@ static void dump_media_session(const char *indent,
if (pj_sockaddr_has_addr(&ii->comp[jj].lcand_addr))
pj_sockaddr_print(&ii->comp[jj].lcand_addr, addr1, sizeof(addr1), 3);
else
strcpy(addr1, "0.0.0.0:0");
pj_ansi_strxcpy(addr1, "0.0.0.0:0", sizeof(addr1));
if (pj_sockaddr_has_addr(&ii->comp[jj].rcand_addr))
pj_sockaddr_print(&ii->comp[jj].rcand_addr, addr2, sizeof(addr2), 3);
else
strcpy(addr2, "0.0.0.0:0");
pj_ansi_strxcpy(addr2, "0.0.0.0:0", sizeof(addr2));
len = pj_ansi_snprintf(p, end-p,
" %s [%d]: L:%s (%c) --> R:%s (%c)\n",
indent, jj,
@ -561,11 +563,12 @@ static void dump_media_session(const char *indent,
sprintf(toh, "(report not available)");
if (xr_stat.rx.stat_sum.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.rx.stat_sum.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -626,11 +629,12 @@ static void dump_media_session(const char *indent,
sprintf(toh, "(report not available)");
if (xr_stat.tx.stat_sum.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.tx.stat_sum.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -698,11 +702,12 @@ static void dump_media_session(const char *indent,
sprintf(jbr, "%d", xr_stat.rx.voip_mtc.rx_config & 0x0F);
if (xr_stat.rx.voip_mtc.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.rx.voip_mtc.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -798,11 +803,12 @@ static void dump_media_session(const char *indent,
sprintf(jbr, "%d", xr_stat.tx.voip_mtc.rx_config & 0x0F);
if (xr_stat.tx.voip_mtc.update.sec == 0)
strcpy(last_update, "never");
pj_ansi_strxcpy(last_update, "never", sizeof(last_update));
else {
pj_gettimeofday(&now);
PJ_TIME_VAL_SUB(now, xr_stat.tx.voip_mtc.update);
sprintf(last_update, "%02ldh:%02ldm:%02ld.%03lds ago",
pj_ansi_snprintf(last_update, sizeof(last_update),
"%02ldh:%02ldm:%02ld.%03lds ago",
now.sec / 3600,
(now.sec % 3600) / 60,
now.sec % 60,
@ -916,7 +922,7 @@ void print_call(const char *title,
dlg = (inv? inv->dlg: call->async_call.dlg);
len = pjsip_hdr_print_on(dlg->remote.info, userinfo, sizeof(userinfo));
if (len < 0)
pj_ansi_strcpy(userinfo, "<--uri too long-->");
pj_ansi_strxcpy(userinfo, "<--uri too long-->", sizeof(userinfo));
else
userinfo[len] = '\0';
@ -927,7 +933,7 @@ void print_call(const char *title,
inv->state),
userinfo);
if (len < 1 || len >= (int)size) {
pj_ansi_strcpy(buf, "<--uri too long-->");
pj_ansi_strxcpy(buf, "<--uri too long-->", size);
len = 18;
} else
buf[len] = '\0';

View File

@ -962,7 +962,8 @@ static pj_bool_t pres_on_rx_request(pjsip_rx_data *rdata)
status = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, dlg->remote.info->uri,
uapres->remote, PJSIP_MAX_URL_SIZE);
if (status < 1)
pj_ansi_strcpy(uapres->remote, "<-- url is too long-->");
pj_ansi_strxcpy(uapres->remote, "<-- url is too long-->",
PJSIP_MAX_URL_SIZE);
else
uapres->remote[status] = '\0';

View File

@ -1633,7 +1633,7 @@ pjsip_redirect_op Endpoint::on_call_redirected(pjsua_call_id call_id,
int len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, target, uristr,
sizeof(uristr));
if (len < 1) {
pj_ansi_strcpy(uristr, "--URI too long--");
pj_ansi_strxcpy(uristr, "--URI too long--", sizeof(uristr));
}
prm.targetUri = string(uristr);
if (e)

View File

@ -553,7 +553,7 @@ int transport_rt_test( pjsip_transport_type_e tp_type,
return -610;
/* Initialize static test data. */
pj_ansi_strcpy(rt_target_uri, target_url);
pj_ansi_strxcpy(rt_target_uri, target_url, sizeof(rt_target_uri));
rt_call_id = pj_str("RT-Call-Id/");
rt_stop = PJ_FALSE;