bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Replace vsprintf with vsnprintf in ext2fs/msg.c


From: Flavio Cruz
Subject: Re: [PATCH] Replace vsprintf with vsnprintf in ext2fs/msg.c
Date: Wed, 9 Nov 2022 00:49:04 -0500

---

Hi

On Sun, Nov 06, 2022 at 11:45:19AM +0100, Samuel Thibault wrote:
> Hello,
> 
> Flavio Cruz, le dim. 06 nov. 2022 01:23:00 -0400, a ecrit:
> > ---
> >  ext2fs/msg.c | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/ext2fs/msg.c b/ext2fs/msg.c
> > index 83939b06..af636b7c 100644
> > --- a/ext2fs/msg.c
> > +++ b/ext2fs/msg.c
> > @@ -38,7 +38,8 @@ int printf (const char *fmt, ...)
> >    return done;
> >  }
> >  
> > -static char error_buf[1024];
> > +#define ERROR_BUF_SIZE 1024
> > +static char error_buf[ERROR_BUF_SIZE];
> >  
> >  void _ext2_error (const char * function, const char * fmt, ...)
> >  {
> > @@ -47,7 +48,7 @@ void _ext2_error (const char * function, const char * 
> > fmt, ...)
> >    pthread_mutex_lock (&printf_lock);
> >  
> >    va_start (args, fmt);
> > -  vsprintf (error_buf, fmt, args);
> > +  vsnprintf (error_buf, ERROR_BUF_SIZE, fmt, args);
> 
> Please rather use sizeof (error_buf).

Done

 ext2fs/msg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ext2fs/msg.c b/ext2fs/msg.c
index 83939b06..b6b1a155 100644
--- a/ext2fs/msg.c
+++ b/ext2fs/msg.c
@@ -47,7 +47,7 @@ void _ext2_error (const char * function, const char * fmt, 
...)
   pthread_mutex_lock (&printf_lock);
 
   va_start (args, fmt);
-  vsprintf (error_buf, fmt, args);
+  vsnprintf (error_buf, sizeof (error_buf), fmt, args);
   va_end (args);
 
   fprintf (stderr, "ext2fs: %s: %s: %s\n", diskfs_disk_name, function, 
error_buf);
@@ -62,7 +62,7 @@ void _ext2_panic (const char * function, const char * fmt, 
...)
   pthread_mutex_lock (&printf_lock);
 
   va_start (args, fmt);
-  vsprintf (error_buf, fmt, args);
+  vsnprintf (error_buf, sizeof (error_buf), fmt, args);
   va_end (args);
 
   fprintf(stderr, "ext2fs: %s: panic: %s: %s\n",
@@ -80,7 +80,7 @@ void ext2_warning (const char * fmt, ...)
   pthread_mutex_lock (&printf_lock);
 
   va_start (args, fmt);
-  vsprintf (error_buf, fmt, args);
+  vsnprintf (error_buf, sizeof (error_buf), fmt, args);
   va_end (args);
 
   fprintf (stderr, "ext2fs: %s: warning: %s\n", diskfs_disk_name, error_buf);
-- 
2.37.2



reply via email to

[Prev in Thread] Current Thread [Next in Thread]