Skip to content

Commit 15e6d57

Browse files
Fix unsigned type "size_t" (#4470)
This commit address the wrong use of "size_t" instead of "ssize_t". The functions that run xattr, like sys_lgetxattr(), sys_lgetxattr() return negative values on error, that is, they return -1. But some of its users were found capture this return in an unsigned "size_t" (implict type conversion). This commit touches the posix xlator files posix-helpers.c and posix-metadata.c, but also the tests get-mdata-xattr.c In posix-helpers.c were found posix_cs_set_state, posix_cs_heal_state and posix_cs_check_status the offending "size_t" in place of "ssize_t" for the variable "xattrsize". In posix-metadata.c was found posix_fetch_mdata_xattr and the variable "size" using an unsigned "size_t" in the exact same way.. In get-mdata-xattr.c, the posix_fetch_mdata_xattr incurs in the exact same offense with the variable "size". This commit changes these cases to the signed "ssize_t". Examples: always true case if (fd) { xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_REMOTE, NULL, 0); if (xattrsize != -1) { always false case xattrsize = sys_fgetxattr(*fd, GF_CS_OBJECT_REMOTE, value, xattrsize + 1); if (xattrsize == -1) { if (value) GF_FREE(value); Signed-off-by: Thales Antunes de Oliveira Barretto <[email protected]>
1 parent 7663679 commit 15e6d57

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

tests/utils/get-mdata-xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ posix_mdata_from_disk(posix_mdata_t *out, posix_mdata_disk_t *in)
7373
static int
7474
posix_fetch_mdata_xattr(const char *real_path, posix_mdata_t *metadata)
7575
{
76-
size_t size = -1;
76+
ssize_t size = -1;
7777
char *value = NULL;
7878
char gfid_str[64] = {0};
7979

xlators/storage/posix/src/posix-helpers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,7 @@ posix_cs_heal_state(xlator_t *this, const char *realpath, int *fd,
30023002
gf_boolean_t downloading = _gf_false;
30033003
int ret = 0;
30043004
gf_cs_obj_state state = GF_CS_ERROR;
3005-
size_t xattrsize = 0;
3005+
ssize_t xattrsize = 0;
30063006

30073007
if (!buf) {
30083008
ret = -1;
@@ -3152,7 +3152,7 @@ posix_cs_check_status(xlator_t *this, const char *realpath, int *fd,
31523152
gf_boolean_t downloading = _gf_false;
31533153
int ret = 0;
31543154
gf_cs_obj_state state = GF_CS_LOCAL;
3155-
size_t xattrsize = 0;
3155+
ssize_t xattrsize = 0;
31563156
int op_errno = 0;
31573157

31583158
if (fd) {
@@ -3253,7 +3253,7 @@ posix_cs_set_state(xlator_t *this, dict_t **rsp, gf_cs_obj_state state,
32533253
{
32543254
int ret = 0;
32553255
char *value = NULL;
3256-
size_t xattrsize = 0;
3256+
ssize_t xattrsize = 0;
32573257

32583258
if (!rsp) {
32593259
ret = -1;

xlators/storage/posix/src/posix-metadata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int
7373
posix_fetch_mdata_xattr(xlator_t *this, const char *real_path_arg, int _fd,
7474
inode_t *inode, posix_mdata_t *metadata, int *op_errno)
7575
{
76-
size_t size = 256;
76+
ssize_t size = 256;
7777
int op_ret = -1;
7878
char *value = NULL;
7979
gf_boolean_t fd_based_fop = _gf_false;

0 commit comments

Comments
 (0)