From: Anoop C S Date: Thu, 25 Apr 2019 11:12:01 +0000 (+0530) Subject: s3/vfs_glusterfs_fuse: Dynamically determine NAME_MAX X-Git-Tag: tdb-1.4.1~293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e28d172b00cadf492c22bd892e2dda3bf2fe2d70;p=thirdparty%2Fsamba.git s3/vfs_glusterfs_fuse: Dynamically determine NAME_MAX This allows the vfs_glusterfs_fuse build to complete on AIX. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13872 Signed-off-by: Anoop C S Reviewed-by: Guenther Deschner Reviewed-by: Ralph Boehme --- diff --git a/source3/modules/vfs_glusterfs_fuse.c b/source3/modules/vfs_glusterfs_fuse.c index 8855cd18d01..0b1de9fcdb2 100644 --- a/source3/modules/vfs_glusterfs_fuse.c +++ b/source3/modules/vfs_glusterfs_fuse.c @@ -28,19 +28,35 @@ static int vfs_gluster_fuse_get_real_filename(struct vfs_handle_struct *handle, char **_found_name) { int ret; - char key_buf[NAME_MAX + 64]; - char val_buf[NAME_MAX + 1]; + char *key_buf = NULL, *val_buf = NULL; + long name_max; char *found_name = NULL; - if (strlen(name) >= NAME_MAX) { + name_max = pathconf(path, _PC_NAME_MAX); + if ((name_max + 1) < 1) { + errno = EINVAL; + return -1; + } + + if (strlen(name) >= name_max) { errno = ENAMETOOLONG; return -1; } - snprintf(key_buf, NAME_MAX + 64, - "glusterfs.get_real_filename:%s", name); + key_buf = talloc_asprintf(mem_ctx, "glusterfs.get_real_filename:%s", + name); + if (key_buf == NULL) { + errno = ENOMEM; + return -1; + } + + val_buf = talloc_zero_array(mem_ctx, char, name_max + 1); + if (val_buf == NULL) { + errno = ENOMEM; + return -1; + } - ret = getxattr(path, key_buf, val_buf, NAME_MAX + 1); + ret = getxattr(path, key_buf, val_buf, name_max + 1); if (ret == -1) { if (errno == ENOATTR) { errno = EOPNOTSUPP; @@ -54,6 +70,10 @@ static int vfs_gluster_fuse_get_real_filename(struct vfs_handle_struct *handle, return -1; } *_found_name = found_name; + + TALLOC_FREE(key_buf); + TALLOC_FREE(val_buf); + return 0; }