Module: sip-router Branch: kamailio_3.0 Commit: a765213ffa3769577dd7438c95737cb6b98bff74 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a765213f...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Tue Feb 2 15:06:34 2010 +0100
core: new param to give outbut buffer size
- int2strbuf requires now outbut buffer size as parameter - safer against misuses, suggested by Andrei Pelinescu-Onciul - if size is less than INT2STR_MAX_LEN, return null pointer
---
ut.h | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/ut.h b/ut.h index 3e4d7a6..3d98e11 100644 --- a/ut.h +++ b/ut.h @@ -294,10 +294,15 @@ static inline char* int2str_base(unsigned int l, int* len, int base)
/* print int to asciiz in a string buffer * - be sure result buffer is at least INT2STR_MAX_LEN in size */ -static inline char* int2strbuf(unsigned int l, char *r, int* len) +static inline char* int2strbuf(unsigned int l, char *r, int r_size, int* len) { int i; - + + if(unlikely(r_size<INT2STR_MAX_LEN)) { + if (len) + *len = 0; + return 0; /* => if someone misuses it => crash (feature no. 1) */ + } i=INT2STR_MAX_LEN-2; r[INT2STR_MAX_LEN-1]=0; /* null terminate */ do{ @@ -316,7 +321,7 @@ extern char ut_buf_int2str[INT2STR_MAX_LEN]; /* returns a pointer to a static buffer containing l in asciiz & sets len */ static inline char* int2str(unsigned long l, int* len) { - return int2strbuf(l, ut_buf_int2str, len); + return int2strbuf(l, ut_buf_int2str, INT2STR_MAX_LEN, len); }
/* Signed INTeger-TO-STRing: convers a long to a string
This fixed the problem. Thank you so much Daniel & Andrei!!
On 02/02/2010 09:09 AM, Daniel-Constantin Mierla wrote:
Module: sip-router Branch: kamailio_3.0 Commit: a765213ffa3769577dd7438c95737cb6b98bff74 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a765213f...
Author: Daniel-Constantin Mierlamiconda@gmail.com Committer: Daniel-Constantin Mierlamiconda@gmail.com Date: Tue Feb 2 15:06:34 2010 +0100
core: new param to give outbut buffer size
- int2strbuf requires now outbut buffer size as parameter
- safer against misuses, suggested by Andrei Pelinescu-Onciul
- if size is less than INT2STR_MAX_LEN, return null pointer
ut.h | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/ut.h b/ut.h index 3e4d7a6..3d98e11 100644 --- a/ut.h +++ b/ut.h @@ -294,10 +294,15 @@ static inline char* int2str_base(unsigned int l, int* len, int base)
/* print int to asciiz in a string buffer
- be sure result buffer is at least INT2STR_MAX_LEN in size */
-static inline char* int2strbuf(unsigned int l, char *r, int* len) +static inline char* int2strbuf(unsigned int l, char *r, int r_size, int* len) { int i;
- if(unlikely(r_size<INT2STR_MAX_LEN)) {
if (len)
*len = 0;
return 0; /* => if someone misuses it => crash (feature no. 1) */
- } i=INT2STR_MAX_LEN-2; r[INT2STR_MAX_LEN-1]=0; /* null terminate */ do{
@@ -316,7 +321,7 @@ extern char ut_buf_int2str[INT2STR_MAX_LEN]; /* returns a pointer to a static buffer containing l in asciiz& sets len */ static inline char* int2str(unsigned long l, int* len) {
- return int2strbuf(l, ut_buf_int2str, len);
return int2strbuf(l, ut_buf_int2str, INT2STR_MAX_LEN, len); }
/* Signed INTeger-TO-STRing: convers a long to a string
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev