Module: sip-router
Branch: tmp/k3.0_sr_backports
Commit: c8cb74d1b15375c0b65ba98dc0234008c64cc3fa
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c8cb74d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
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
(cherry picked from commit a765213ffa3769577dd7438c95737cb6b98bff74)
---
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