Skip to content

Traverse xattrs using a pointer to xattr instead of snprintf() its value #4363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libglusterfs/src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ dict_lookup(dict_t *this, char *key, data_t **data)
}

static int32_t
dict_set_lk(dict_t *this, char *key, const int key_len, data_t *value,
dict_set_lk(dict_t *this, const char *key, const int key_len, data_t *value,
gf_boolean_t replace)
{
data_pair_t *pair;
Expand Down Expand Up @@ -394,7 +394,7 @@ dict_set_lk(dict_t *this, char *key, const int key_len, data_t *value,
}

int32_t
dict_setn(dict_t *this, char *key, const int keylen, data_t *value)
dict_setn(dict_t *this, const char *key, const int keylen, data_t *value)
{
int32_t ret;

Expand Down Expand Up @@ -2151,7 +2151,7 @@ dict_set_static_ptr(dict_t *this, char *key, void *ptr)
}

int
dict_set_dynptr(dict_t *this, char *key, void *ptr, size_t len)
dict_set_dynptr(dict_t *this, const char *key, void *ptr, size_t len)
{
data_t *data = data_from_dynptr(ptr, len);
int ret = 0;
Expand Down
6 changes: 3 additions & 3 deletions libglusterfs/src/glusterfs/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ is_data_equal(data_t *one, data_t *two);

/* function to set a key/value pair (overwrite existing if matches the key */
int32_t
dict_setn(dict_t *this, char *key, const int keylen, data_t *value);
dict_setn(dict_t *this, const char *key, const int keylen, data_t *value);

static inline int32_t
dict_set(dict_t *this, char *key, data_t *value)
dict_set(dict_t *this, const char *key, data_t *value)
{
return dict_setn(this, key, strlen(key), value);
}
Expand Down Expand Up @@ -369,7 +369,7 @@ dict_get_ptr(dict_t *this, char *key, void **ptr);
GF_MUST_CHECK int
dict_get_ptr_and_len(dict_t *this, char *key, void **ptr, int *len);
GF_MUST_CHECK int
dict_set_dynptr(dict_t *this, char *key, void *ptr, size_t size);
dict_set_dynptr(dict_t *this, const char *key, void *ptr, size_t size);

GF_MUST_CHECK int
dict_get_bin(dict_t *this, char *key, void **ptr);
Expand Down
8 changes: 3 additions & 5 deletions xlators/storage/posix/src/posix-gfid-path.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
char *value = NULL;
size_t remaining_size = 0;
size_t bytes = 0;
char keybuffer[4096] = {
0,
};
char *keybuffer = NULL;

uuid_t pargfid = {
0,
Expand Down Expand Up @@ -137,8 +135,8 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
remaining_size = size;
list_offset = 0;
while (remaining_size > 0) {
len = snprintf(keybuffer, sizeof(keybuffer), "%s",
list + list_offset);
keybuffer = list + list_offset;
len = strlen(keybuffer);

if (!posix_is_gfid2path_xattr(keybuffer)) {
goto ignore;
Expand Down
8 changes: 4 additions & 4 deletions xlators/storage/posix/src/posix-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ _posix_get_marker_all_contributions(posix_xattr_filler_t *filler)
ssize_t size = -1, remaining_size = -1, list_offset = 0;
int ret = -1;
int len;
char *list = NULL, key[4096] = {
0,
};
char *list = NULL;
char *key;

if (filler->real_path)
size = sys_llistxattr(filler->real_path, NULL, 0);
Expand Down Expand Up @@ -364,7 +363,8 @@ _posix_get_marker_all_contributions(posix_xattr_filler_t *filler)
list_offset = 0;

while (remaining_size > 0) {
len = snprintf(key, sizeof(key), "%s", list + list_offset);
key = list + list_offset;
len = strlen(key);
if (fnmatch(marker_contri_key, key, 0) == 0) {
(void)_posix_xattr_get_set_from_backend(filler, key);
}
Expand Down
27 changes: 18 additions & 9 deletions xlators/storage/posix/src/posix-inode-fd-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3457,9 +3457,7 @@ posix_get_ancestry_non_directory(xlator_t *this, inode_t *leaf_inode,
inode_t *parent = NULL;
loc_t *loc = NULL;
char *leaf_path = NULL;
char key[4096] = {
0,
};
char *key;
char dirpath[PATH_MAX] = {
0,
};
Expand Down Expand Up @@ -3533,7 +3531,8 @@ posix_get_ancestry_non_directory(xlator_t *this, inode_t *leaf_inode,
}

while (remaining_size > 0) {
len = snprintf(key, sizeof(key), "%s", list + list_offset);
key = list + list_offset;
len = strlen(key);
if (strncmp(key, PGFID_XATTR_KEY_PREFIX,
SLEN(PGFID_XATTR_KEY_PREFIX)) != 0)
goto next;
Expand Down Expand Up @@ -4034,10 +4033,9 @@ posix_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
}
remaining_size = size;
list_offset = 0;
keybuffer = alloca(XATTR_KEY_BUF_SIZE);
while (remaining_size > 0) {
keybuff_len = snprintf(keybuffer, XATTR_KEY_BUF_SIZE, "%s",
list + list_offset);
keybuffer = list + list_offset;
keybuff_len = strlen(keybuffer);

ret = posix_handle_georep_xattrs(frame, keybuffer, NULL, _gf_false);
if (ret == -1)
Expand Down Expand Up @@ -4163,9 +4161,13 @@ posix_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
char *list = NULL;
dict_t *dict = NULL;
int ret = -1;
#ifdef GF_DARWIN_HOST_OS
char key[4096] = {
0,
};
#else
const char *key = NULL;
#endif
int key_len;
char *value_buf = NULL;
gf_boolean_t have_val = _gf_false;
Expand Down Expand Up @@ -4279,8 +4281,11 @@ posix_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
value_buf = alloca(XATTR_VAL_BUF_SIZE);

if (name) {
#ifndef GF_DARWIN_HOST_OS
key = name;
key_len = strlen(key);
#else
key_len = snprintf(key, sizeof(key), "%s", name);
#ifdef GF_DARWIN_HOST_OS
struct posix_private *priv = NULL;
priv = this->private;
if (priv->xattr_user_namespace == XATTR_STRIP) {
Expand Down Expand Up @@ -4403,8 +4408,12 @@ posix_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
while (remaining_size > 0) {
if (*(list + list_offset) == '\0')
break;

#ifndef GF_DARWIN_HOST_OS
key = list + list_offset;
key_len = strlen(key);
#else
key_len = snprintf(key, sizeof(key), "%s", list + list_offset);
#endif
have_val = _gf_false;
size = sys_fgetxattr(_fd, key, value_buf, XATTR_VAL_BUF_SIZE - 1);
if (size >= 0) {
Expand Down