Minor changes based on reviews

This commit is contained in:
bennylp 2023-03-29 11:28:27 +07:00
parent 336bc36e28
commit 52fe443ea1
19 changed files with 133 additions and 117 deletions

View File

@ -1,4 +1,5 @@
# Scheduled scan, only runs on master
# Scheduled scan, only runs on master (see
# https://stackoverflow.com/a/58800550)
name: "Coverity Scan (Daily)"
@ -7,13 +8,11 @@ on:
- cron: '0 12 * * *' # Daily at 12:00 UTC
jobs:
ubuntu-default-full-bundle:
ubuntu-full-bundle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: master
- name: run.sh
run: tests/coverity-scan/run.sh -t
run: tests/coverity-scan/run.sh
env:
COV_TOKEN: ${{ secrets.PJSIP_COVERITY_SCAN_TOKEN }}

View File

@ -3,14 +3,14 @@
name: "Coverity Scan (Manual)"
on: [workflow_dispatch, pull_request]
on: [workflow_dispatch]
jobs:
ubuntu-default-full-bundle:
ubuntu-full-bundle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: run.sh
run: tests/coverity-scan/run.sh -t
run: tests/coverity-scan/run.sh
env:
COV_TOKEN: ${{ secrets.PJSIP_COVERITY_SCAN_TOKEN }}

View File

@ -849,7 +849,7 @@ PJ_INLINE(void*) pj_memchr(const void *buf, int c, pj_size_t size)
*
* @param dst The destination string.
* @param src The source string.
* @param dst_size The size of the destination string.
* @param dst_size The full size of the destination string buffer.
*
* @return The number of characters copied (not including the trailing NUL) or
* -PJ_ETOOBIG if the destination buffer wasn't big enough,
@ -865,7 +865,7 @@ PJ_DECL(int) pj_ansi_strxcpy(char *dst, const char *src, pj_size_t dst_size);
*
* @param dst The destination string.
* @param src The source string.
* @param dst_size The size of the destination string.
* @param dst_size The full size of the destination string buffer.
*
* @return The number of characters copied (not including the trailing NUL) or
* -PJ_ETOOBIG if the destination buffer wasn't big enough,
@ -884,7 +884,7 @@ PJ_DECL(int) pj_ansi_strxcpy2(char *dst, const pj_str_t *src,
*
* @param dst The destination string.
* @param src The source string.
* @param dst_size The size of the destination string.
* @param dst_size The full size of the destination string buffer.
*
* @return Final length of dst string (not including the trailing NUL) or
* -PJ_ETOOBIG if the destination buffer wasn't big enough,

View File

@ -2381,14 +2381,14 @@ static pj_status_t ssl_do_handshake(pj_ssl_sock_t *ssock)
len *= 2;
if (len >= BUF_SIZE) len = BUF_SIZE;
for (i = 0; i < len; i+=2)
pj_ansi_snprintf(buf+i, len-i, "%02X", sid[i/2]);
pj_ansi_snprintf(buf+i, sizeof(buf)-i, "%02X", sid[i/2]);
buf[len] = '\0';
PJ_LOG(5, (THIS_FILE, "Session id: %s", buf));
sctx = SSL_SESSION_get0_id_context(sess, &len);
if (len >= BUF_SIZE) len = BUF_SIZE;
for (i = 0; i < len; i++)
pj_ansi_snprintf(buf + i, len-i, "%d", sctx[i]);
pj_ansi_snprintf(buf + i, sizeof(buf)-i, "%d", sctx[i]);
buf[len] = '\0';
PJ_LOG(5, (THIS_FILE, "Session id context: %s", buf));
}

View File

@ -295,11 +295,14 @@ static int verify_strxcpy(const char *src, int dst_size, int exp_ret,
const char *exp_dst)
{
char dst[6];
char GUARD = '@';
const char GUARDS[2] = {'@', '\0'};
int i, ret;
PJ_ASSERT_RETURN(src && dst_size <= 5, -700);
for (int ig=0; ig<sizeof(GUARDS); ++ig) {
char GUARD = GUARDS[ig];
memset(dst, GUARD, sizeof(dst));
ret = pj_ansi_strxcpy(dst, src, dst_size);
@ -314,20 +317,22 @@ static int verify_strxcpy(const char *src, int dst_size, int exp_ret,
/* expected dst content */
if (exp_dst) {
if (strcmp(dst, exp_dst)) {
PJ_LOG(3,("", " strxcpy \"%s\", dst_size=%d: dst content mismatch: \"%s\"!=\"%s\"",
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) {
for (i=exp_dst?strlen(exp_dst)+1:0; i<(int)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;
}
@ -394,19 +399,24 @@ static int verify_strxcpy2(const pj_str_t *src, int dst_size, int exp_ret,
const char *exp_dst)
{
char dst[6];
char GUARD = '@';
const char GUARDS[2] = {'@', '\0'};
int i, ret;
PJ_ASSERT_RETURN(src && dst_size <= 5, -720);
for (int ig=0; ig<sizeof(GUARDS); ++ig) {
char GUARD = GUARDS[ig];
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));
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;
}
@ -431,6 +441,7 @@ static int verify_strxcpy2(const pj_str_t *src, int dst_size, int exp_ret,
return -728;
}
}
}
return 0;
}
@ -514,13 +525,16 @@ 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 = '@';
const char GUARDS[2] = {'@', '\0'};
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);
for (int ig=0; ig<sizeof(GUARDS); ++ig) {
char GUARD = GUARDS[ig];
memset(dst, GUARD, sizeof(dst));
if (dst_size) {
ret = pj_ansi_strxcpy(dst, cdst, dst_size);
@ -547,7 +561,7 @@ static int verify_strxcat(const char *cdst, const char *src, int dst_size,
}
/* verify not writing past buffer */
for (i=exp_dst?strlen(exp_dst)+1:0; i<sizeof(dst); ++i) {
for (i=exp_dst?strlen(exp_dst)+1:0; i<(int)sizeof(dst); ++i) {
if (dst[i] != GUARD) {
PJ_LOG(3,("", " strxcat \"%s\", \"%s\", dst_size=%d: "
"overflow at %d",
@ -555,6 +569,7 @@ static int verify_strxcat(const char *cdst, const char *src, int dst_size,
return -738;
}
}
}
return 0;
}

View File

@ -594,7 +594,9 @@ struct TsxStateEventSrc
pj_status_t status; /**< Transport error status. */
GenericData data; /**< Generic data. */
TsxStateEventSrc() : timer(NULL), status(), data(NULL) {}
TsxStateEventSrc()
: timer(NULL), status(PJ_SUCCESS), data(NULL)
{}
};
/**

View File

@ -3519,7 +3519,7 @@ pj_status_t pjsua_acc_get_uac_addr(pjsua_acc_id acc_id,
{
int i;
for (i = 0; i < PJ_ARRAY_SIZE(pjsua_var.tpdata); i++) {
for (i = 0; i < (int)PJ_ARRAY_SIZE(pjsua_var.tpdata); i++) {
if (tfla2_prm.ret_tp==(const void *)pjsua_var.tpdata[i].data.tp) {
if (pjsua_var.tpdata[i].has_bound_addr) {
pj_strdup(pool, &addr->host,

View File

@ -1772,7 +1772,7 @@ PJ_DEF(pj_status_t) pjsua_enum_snd_devs( pjmedia_snd_dev_info info[],
if (status != PJ_SUCCESS)
return status;
pj_memcpy(info[i].name, ai.name, sizeof(info[i].name));
pj_ansi_strxcpy(info[i].name, ai.name, sizeof(info[i].name));
info[i].input_count = ai.input_count;
info[i].output_count = ai.output_count;
info[i].default_samples_per_sec = ai.default_samples_per_sec;

View File

@ -695,7 +695,7 @@ static pj_status_t apply_call_setting(pjsua_call *call,
/* If call is established or media channel hasn't been initialized,
* reinit media channel.
*/
if (call-> inv &&
if (call->inv &&
((call->inv->state == PJSIP_INV_STATE_CONNECTING &&
call->med_cnt == 0) ||
(call->inv->state == PJSIP_INV_STATE_CONFIRMED) ||