diff options
author | Jianhong Yin <jiyin@redhat.com> | 2015-11-04 16:28:47 -0500 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2015-11-04 16:28:47 -0500 |
commit | 67a0768370a54100c77e58f611e1d1fceb93e2c0 (patch) | |
tree | e403bdb61965b4575e303788d475fcb9252d4cb8 /utils/exportfs/exportfs.c | |
parent | 19e6ba690c7e9674dae006cfce89f638c8d8edab (diff) | |
download | nfs-utils-67a0768370a54100c77e58f611e1d1fceb93e2c0.tar.gz nfs-utils-67a0768370a54100c77e58f611e1d1fceb93e2c0.tar.xz nfs-utils-67a0768370a54100c77e58f611e1d1fceb93e2c0.zip |
exportfs: Fix buf size in test_export() dump()
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/
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/exportfs/exportfs.c')
-rw-r--r-- | utils/exportfs/exportfs.c | 13 |
1 files 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; |