[sr-dev] [SOLVED] git:kamailio_3.0: core: new param to give outbut buffer size

Alex Balashov abalashov at evaristesys.com
Wed Feb 3 00:11:47 CET 2010


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=a765213ffa3769577dd7438c95737cb6b98bff74
>
> Author: Daniel-Constantin Mierla<miconda at gmail.com>
> Committer: Daniel-Constantin Mierla<miconda at 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 at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev


-- 
Alex Balashov - Principal
Evariste Systems LLC

Tel    : +1 678-954-0670
Direct : +1 678-954-0671
Web    : http://www.evaristesys.com/



More information about the sr-dev mailing list