diff mbox

ARM: plat-samsung: using vsnprintf instead of vsprintf for the limit buffer length 256

Message ID 50FD178E.9090105@asianux.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chen Gang Jan. 21, 2013, 10:25 a.m. UTC
the buff size is 256, so need use vsnprintf instead of vsprintf.

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 arch/arm/plat-samsung/pm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ben Dooks Jan. 21, 2013, 1:56 p.m. UTC | #1
On Mon, Jan 21, 2013 at 06:25:18PM +0800, Chen Gang wrote:
> 
>   the buff size is 256, so need use vsnprintf instead of vsprintf.
> 
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
>  arch/arm/plat-samsung/pm.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/plat-samsung/pm.c b/arch/arm/plat-samsung/pm.c
> index 1507028..8d07b45 100644
> --- a/arch/arm/plat-samsung/pm.c
> +++ b/arch/arm/plat-samsung/pm.c
> @@ -51,7 +51,7 @@ void s3c_pm_dbg(const char *fmt, ...)
>  	char buff[256];
>  
>  	va_start(va, fmt);
> -	vsprintf(buff, fmt, va);
> +	vsnprintf(buff, 256, fmt, va);

How about: vsnprintf(buff, sizeof(buff), fmt, va);

It means we do not end up assuming the size of 'buff' and will be correct
if the code is changed to declare 'buff' to be a different size.
Russell King - ARM Linux Jan. 21, 2013, 4 p.m. UTC | #2
On Mon, Jan 21, 2013 at 06:25:18PM +0800, Chen Gang wrote:
> 
>   the buff size is 256, so need use vsnprintf instead of vsprintf.
> 
> Signed-off-by: Chen Gang <gang.chen@asianux.com>
> ---
>  arch/arm/plat-samsung/pm.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/plat-samsung/pm.c b/arch/arm/plat-samsung/pm.c
> index 1507028..8d07b45 100644
> --- a/arch/arm/plat-samsung/pm.c
> +++ b/arch/arm/plat-samsung/pm.c
> @@ -51,7 +51,7 @@ void s3c_pm_dbg(const char *fmt, ...)
>  	char buff[256];
>  
>  	va_start(va, fmt);
> -	vsprintf(buff, fmt, va);
> +	vsnprintf(buff, 256, fmt, va);

sizeof(buff) would be better here so that it depends on the actual buffer
size.
Chen Gang Jan. 22, 2013, 1 a.m. UTC | #3
? 2013?01?21? 21:56, Ben Dooks ??:
> How about: vsnprintf(buff, sizeof(buff), fmt, va);
> 
> It means we do not end up assuming the size of 'buff' and will be correct
> if the code is changed to declare 'buff' to be a different size.

  thank you, I will send patch v2.

  :-)
Chen Gang Jan. 22, 2013, 1 a.m. UTC | #4
? 2013?01?22? 00:00, Russell King - ARM Linux ??:
> sizeof(buff) would be better here so that it depends on the actual buffer
> size.

  thank you, I will send patch v2.

  :-)
diff mbox

Patch

diff --git a/arch/arm/plat-samsung/pm.c b/arch/arm/plat-samsung/pm.c
index 1507028..8d07b45 100644
--- a/arch/arm/plat-samsung/pm.c
+++ b/arch/arm/plat-samsung/pm.c
@@ -51,7 +51,7 @@  void s3c_pm_dbg(const char *fmt, ...)
 	char buff[256];
 
 	va_start(va, fmt);
-	vsprintf(buff, fmt, va);
+	vsnprintf(buff, 256, fmt, va);
 	va_end(va);
 
 	printascii(buff);