summaryrefslogtreecommitdiff
path: root/pjnath
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2013-10-08 09:08:13 +0000
committerBenny Prijono <bennylp@teluu.com>2013-10-08 09:08:13 +0000
commit7369d96f8361c523a7ae4753391a9a7336a89fb8 (patch)
tree64afc15371dfb0cafe15648537d33d4ad0c4c38a /pjnath
parent476648f068a362857304aca7b383f700a304d59e (diff)
Re #1703: fixing general bugs. First installment: correct handling of snprintf return value
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4613 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjnath')
-rw-r--r--pjnath/src/pjnath/errno.c8
-rw-r--r--pjnath/src/pjnath/stun_msg.c3
2 files changed, 6 insertions, 5 deletions
diff --git a/pjnath/src/pjnath/errno.c b/pjnath/src/pjnath/errno.c
index df4bdcb7..a6bb471a 100644
--- a/pjnath/src/pjnath/errno.c
+++ b/pjnath/src/pjnath/errno.c
@@ -133,8 +133,8 @@ static pj_str_t pjnath_strerror(pj_status_t statcode,
errstr.slen = pj_ansi_snprintf(buf, bufsize,
"Unknown pjnath error %d",
statcode);
- if (errstr.slen < 0) errstr.slen = 0;
- else if (errstr.slen > (int)bufsize) errstr.slen = bufsize;
+ if (errstr.slen < 1 || errstr.slen >= (int)bufsize)
+ errstr.slen = bufsize-1;
return errstr;
}
@@ -164,8 +164,8 @@ static pj_str_t pjnath_strerror2(pj_status_t statcode,
buf[bufsize-1] = '\0';
}
- if (errstr.slen < 0) errstr.slen = 0;
- else if (errstr.slen > (int)bufsize) errstr.slen = bufsize;
+ if (errstr.slen < 1 || errstr.slen >= (int)bufsize)
+ errstr.slen = bufsize-1;
return errstr;
}
diff --git a/pjnath/src/pjnath/stun_msg.c b/pjnath/src/pjnath/stun_msg.c
index ffdf09f1..cce914e2 100644
--- a/pjnath/src/pjnath/stun_msg.c
+++ b/pjnath/src/pjnath/stun_msg.c
@@ -2451,7 +2451,8 @@ PJ_DEF(pj_status_t) pj_stun_msg_decode(pj_pool_t *pool,
"%s in %s",
err_msg1,
pj_stun_get_attr_name(attr_type));
-
+ if (e.slen < 1 || e.slen >= (int)sizeof(err_msg2))
+ e.slen = sizeof(err_msg2) - 1;
pj_stun_msg_create_response(pool, msg,
PJ_STUN_SC_BAD_REQUEST,
&e, p_response);