All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] exportfs: Fix buf size in test_export() dump().
@ 2015-11-04  3:43 stevens.yin
  2015-11-04 21:54 ` Steve Dickson
  0 siblings, 1 reply; 3+ messages in thread
From: stevens.yin @ 2015-11-04  3:43 UTC (permalink / raw)
  To: linux-nfs; +Cc: steved, Jianhong Yin

From: Jianhong Yin <jiyin@redhat.com>

The buf[] size in test_export() is not enough for NFS_MAXPATHLEN
+ prefix/suffix proto string. Fix it and same issue in dump().
And just to be on the safe side, %s/sprintf/snprintf/
---
 utils/exportfs/exportfs.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 8758231..c7a79a6 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -499,9 +499,10 @@ unexportfs(char *arg, int verbose)
 
 static int can_test(void)
 {
-	char buf[1024];
+	char buf[1024] = { 0 };
 	int fd;
 	int n;
+	size_t bufsiz = sizeof(buf);
 
 	fd = open("/proc/net/rpc/auth.unix.ip/channel", O_WRONLY);
 	if (fd < 0)
@@ -514,9 +515,9 @@ static int can_test(void)
 	 * commit 2f74f972  (sunrpc: prepare NFS for 2038).
 	 */
 	if (time(NULL) > INT_TO_LONG_THRESHOLD_SECS)
-		sprintf(buf, "nfsd 0.0.0.0 %ld -test-client-\n", LONG_MAX);
+		snprintf(buf, bufsiz-1, "nfsd 0.0.0.0 %ld -test-client-\n", LONG_MAX);
 	else
-		sprintf(buf, "nfsd 0.0.0.0 %d -test-client-\n", INT_MAX);
+		snprintf(buf, bufsiz-1, "nfsd 0.0.0.0 %d -test-client-\n", INT_MAX);
 
 	n = write(fd, buf, strlen(buf));
 	close(fd);
@@ -532,7 +533,8 @@ static int can_test(void)
 
 static int test_export(char *path, int with_fsid)
 {
-	char buf[1024];
+	/* beside max path, buf size should take protocol str into account */
+	char buf[NFS_MAXPATHLEN+1+64] = { 0 };
 	char *bp = buf;
 	int len = sizeof(buf);
 	int fd, n;
@@ -758,7 +760,8 @@ dumpopt(char c, char *fmt, ...)
 static void
 dump(int verbose, int export_format)
 {
-	char buf[1024];
+	/* buf[] size should >= sizeof(struct exportent->e_path) */
+	char buf[NFS_MAXPATHLEN+1] = { 0 };
 	char *bp;
 	int len;
 	nfs_export	*exp;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] exportfs: Fix buf size in test_export() dump().
  2015-11-04  3:43 [PATCH] exportfs: Fix buf size in test_export() dump() stevens.yin
@ 2015-11-04 21:54 ` Steve Dickson
  2015-11-05  0:43   ` Jianhong Yin
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Dickson @ 2015-11-04 21:54 UTC (permalink / raw)
  To: stevens.yin, linux-nfs



On 11/03/2015 10:43 PM, stevens.yin wrote:
> From: Jianhong Yin <jiyin@redhat.com>
> 
> The buf[] size in test_export() is not enough for NFS_MAXPATHLEN
> + prefix/suffix proto string. Fix it and same issue in dump().
> And just to be on the safe side, %s/sprintf/snprintf/
Next time please add a proper Signed-off-by line. Since
I do know the history of this patch I did the Signed-off-by.

Committed...

steved.

> ---
>  utils/exportfs/exportfs.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index 8758231..c7a79a6 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -499,9 +499,10 @@ unexportfs(char *arg, int verbose)
>  
>  static int can_test(void)
>  {
> -	char buf[1024];
> +	char buf[1024] = { 0 };
>  	int fd;
>  	int n;
> +	size_t bufsiz = sizeof(buf);
>  
>  	fd = open("/proc/net/rpc/auth.unix.ip/channel", O_WRONLY);
>  	if (fd < 0)
> @@ -514,9 +515,9 @@ static int can_test(void)
>  	 * commit 2f74f972  (sunrpc: prepare NFS for 2038).
>  	 */
>  	if (time(NULL) > INT_TO_LONG_THRESHOLD_SECS)
> -		sprintf(buf, "nfsd 0.0.0.0 %ld -test-client-\n", LONG_MAX);
> +		snprintf(buf, bufsiz-1, "nfsd 0.0.0.0 %ld -test-client-\n", LONG_MAX);
>  	else
> -		sprintf(buf, "nfsd 0.0.0.0 %d -test-client-\n", INT_MAX);
> +		snprintf(buf, bufsiz-1, "nfsd 0.0.0.0 %d -test-client-\n", INT_MAX);
>  
>  	n = write(fd, buf, strlen(buf));
>  	close(fd);
> @@ -532,7 +533,8 @@ static int can_test(void)
>  
>  static int test_export(char *path, int with_fsid)
>  {
> -	char buf[1024];
> +	/* beside max path, buf size should take protocol str into account */
> +	char buf[NFS_MAXPATHLEN+1+64] = { 0 };
>  	char *bp = buf;
>  	int len = sizeof(buf);
>  	int fd, n;
> @@ -758,7 +760,8 @@ dumpopt(char c, char *fmt, ...)
>  static void
>  dump(int verbose, int export_format)
>  {
> -	char buf[1024];
> +	/* buf[] size should >= sizeof(struct exportent->e_path) */
> +	char buf[NFS_MAXPATHLEN+1] = { 0 };
>  	char *bp;
>  	int len;
>  	nfs_export	*exp;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] exportfs: Fix buf size in test_export() dump().
  2015-11-04 21:54 ` Steve Dickson
@ 2015-11-05  0:43   ` Jianhong Yin
  0 siblings, 0 replies; 3+ messages in thread
From: Jianhong Yin @ 2015-11-05  0:43 UTC (permalink / raw)
  To: Steve Dickson; +Cc: linux-nfs



----- 原始邮件 -----
> 发件人: "Steve Dickson" <SteveD@redhat.com>
> 收件人: "stevens.yin" <jiyin@redhat.com>, linux-nfs@vger.kernel.org
> 发送时间: 星期四, 2015年 11 月 05日 上午 5:54:19
> 主题: Re: [PATCH] exportfs: Fix buf size in test_export() dump().
> 
> 
> 
> On 11/03/2015 10:43 PM, stevens.yin wrote:
> > From: Jianhong Yin <jiyin@redhat.com>
> > 
> > The buf[] size in test_export() is not enough for NFS_MAXPATHLEN
> > + prefix/suffix proto string. Fix it and same issue in dump().
> > And just to be on the safe side, %s/sprintf/snprintf/
> Next time please add a proper Signed-off-by line. Since
> I do know the history of this patch I did the Signed-off-by.
Got it, thanks!

> 
> Committed...
> 
> steved.
> 
> > ---
> >  utils/exportfs/exportfs.c | 13 ++++++++-----
> >  1 file changed, 8 insertions(+), 5 deletions(-)
> > 
> > diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> > index 8758231..c7a79a6 100644
> > --- a/utils/exportfs/exportfs.c
> > +++ b/utils/exportfs/exportfs.c
> > @@ -499,9 +499,10 @@ unexportfs(char *arg, int verbose)
> >  
> >  static int can_test(void)
> >  {
> > -	char buf[1024];
> > +	char buf[1024] = { 0 };
> >  	int fd;
> >  	int n;
> > +	size_t bufsiz = sizeof(buf);
> >  
> >  	fd = open("/proc/net/rpc/auth.unix.ip/channel", O_WRONLY);
> >  	if (fd < 0)
> > @@ -514,9 +515,9 @@ static int can_test(void)
> >  	 * commit 2f74f972  (sunrpc: prepare NFS for 2038).
> >  	 */
> >  	if (time(NULL) > INT_TO_LONG_THRESHOLD_SECS)
> > -		sprintf(buf, "nfsd 0.0.0.0 %ld -test-client-\n", LONG_MAX);
> > +		snprintf(buf, bufsiz-1, "nfsd 0.0.0.0 %ld -test-client-\n", LONG_MAX);
> >  	else
> > -		sprintf(buf, "nfsd 0.0.0.0 %d -test-client-\n", INT_MAX);
> > +		snprintf(buf, bufsiz-1, "nfsd 0.0.0.0 %d -test-client-\n", INT_MAX);
> >  
> >  	n = write(fd, buf, strlen(buf));
> >  	close(fd);
> > @@ -532,7 +533,8 @@ static int can_test(void)
> >  
> >  static int test_export(char *path, int with_fsid)
> >  {
> > -	char buf[1024];
> > +	/* beside max path, buf size should take protocol str into account */
> > +	char buf[NFS_MAXPATHLEN+1+64] = { 0 };
> >  	char *bp = buf;
> >  	int len = sizeof(buf);
> >  	int fd, n;
> > @@ -758,7 +760,8 @@ dumpopt(char c, char *fmt, ...)
> >  static void
> >  dump(int verbose, int export_format)
> >  {
> > -	char buf[1024];
> > +	/* buf[] size should >= sizeof(struct exportent->e_path) */
> > +	char buf[NFS_MAXPATHLEN+1] = { 0 };
> >  	char *bp;
> >  	int len;
> >  	nfs_export	*exp;
> > 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-05  0:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-04  3:43 [PATCH] exportfs: Fix buf size in test_export() dump() stevens.yin
2015-11-04 21:54 ` Steve Dickson
2015-11-05  0:43   ` Jianhong Yin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.