[PATCH] preallocate result for glfs_realpath in vfs_glusterfs
Michael Adam
obnox at samba.org
Fri Oct 21 06:36:34 UTC 2016
On 2016-10-21 at 11:46 +0530, Anoop C S wrote:
> On Fri, 2016-10-21 at 00:57 +0200, Michael Adam wrote:
> > Hi all,
> >
> > due to a recent change in glusterfs
> > https://review.gluster.org/#/c/15332/ ,
> > it is now wrong to just free the result
> > of glfs_realpath(). This needs to be discussed,
> > but here is a patch that makes us indedpendent
> > of the allocation mechanism used by glfs_realpath()
> > by handing in a pre-malloced result string.
> >
> > This is based on discussions I had with
> > Rajesh and Anoop today.
> >
> > Reviews appreciated!
> > Rajesh/Anoop, please also confirm this approach!
> >
>
> I can confirm that with this patch smbd no longer segfaults while mounting the share via Windows,
> CIFS and smbclient.
>
> Since glfs_realpath honours pre-allocated memory this would be the most favourable approach.
Thanks for confirming Anoop!
Rajesh further pointed out to me that the code should
free the pre-allocated string if glfs_realpath fails,
which is obviously true.
Attached find an updated version of the patch.
Cheers - Michael
-------------- next part --------------
From 803506a0d74c0d69f44cb0c0643395b7c32c1b57 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Fri, 21 Oct 2016 00:15:06 +0200
Subject: [PATCH] vfs:glusterfs: preallocate result for glfs_realpath
This makes us independent of the allocation
method used inside glfs_realpath.
Signed-off-by: Michael Adam <obnox at samba.org>
---
source3/modules/vfs_glusterfs.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
index 3e15ce6..1c9be2d 100644
--- a/source3/modules/vfs_glusterfs.c
+++ b/source3/modules/vfs_glusterfs.c
@@ -1140,7 +1140,20 @@ static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
static char *vfs_gluster_realpath(struct vfs_handle_struct *handle,
const char *path)
{
- return glfs_realpath(handle->data, path, 0);
+ char *result = NULL;
+ char *resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
+
+ if (resolved_path == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ result = glfs_realpath(handle->data, path, resolved_path);
+ if (result == NULL) {
+ SAFE_FREE(resolved_path);
+ }
+
+ return result;
}
static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
--
2.7.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20161021/5d4a2328/signature.sig>
More information about the samba-technical
mailing list