diff options
author | Xavi Hernandez <xhernandez@redhat.com> | 2018-07-06 20:23:35 +0200 |
---|---|---|
committer | Xavi Hernandez <xhernandez@redhat.com> | 2018-07-10 16:28:24 +0200 |
commit | 6dc5dfef819cad69d6d4b4c1c305efa74236ad84 (patch) | |
tree | 6b325caf478689d8113279191ca1916e5f5b32ea /xlators/storage/posix/src/posix-helpers.c | |
parent | 03f1f5bdc46076178f1afdf8e2a76c5b973fe11f (diff) |
Fix compile warnings
This patch fixes compile warnings that appear with newer compilers. The
solution applied is only to remove the warnings, but it doesn't always
solve the problem in the best way. It assumes that the problem will never
happen, as the previous code assumed.
Change-Id: I6e8470d6c2e2dbd3bd7d324b5fd2f92ffdc3d6ec
updates: bz#1193929
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix-helpers.c')
-rw-r--r-- | xlators/storage/posix/src/posix-helpers.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index 236f2e61c33..b02adf308ff 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -2687,8 +2687,12 @@ posix_resolve_dirgfid_to_path (const uuid_t dirgfid, const char *brick_path, (void) snprintf (gpath, PATH_MAX, "%s/.glusterfs/", brick_path); while (!(__is_root_gfid (pargfid))) { - snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath, - pargfid[0], pargfid[1], uuid_utoa (pargfid)); + len = snprintf (dir_handle, PATH_MAX, "%s/%02x/%02x/%s", gpath, + pargfid[0], pargfid[1], uuid_utoa (pargfid)); + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; + } len = sys_readlink (dir_handle, linkname, PATH_MAX); if (len < 0) { @@ -2707,10 +2711,14 @@ posix_resolve_dirgfid_to_path (const uuid_t dirgfid, const char *brick_path, dir_name = strtok_r (NULL, "/", &saveptr); if (strlen(pre_dir_name) != 0) { /* Remove '/' at the end */ - snprintf (result, PATH_MAX, "%s/%s", dir_name, - pre_dir_name); + len = snprintf (result, PATH_MAX, "%s/%s", dir_name, + pre_dir_name); } else { - snprintf (result, PATH_MAX, "%s", dir_name); + len = snprintf (result, PATH_MAX, "%s", dir_name); + } + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; } strncpy (pre_dir_name, result, sizeof(pre_dir_name)); @@ -2720,12 +2728,20 @@ posix_resolve_dirgfid_to_path (const uuid_t dirgfid, const char *brick_path, } if (bname) { - snprintf (result1, PATH_MAX, "/%s/%s", result, bname); + len = snprintf (result1, PATH_MAX, "/%s/%s", result, bname); } else { - snprintf (result1, PATH_MAX, "/%s", result); + len = snprintf (result1, PATH_MAX, "/%s", result); + } + if ((len < 0) || (len >= PATH_MAX)) { + ret = -1; + goto out; } *path = gf_strdup (result1); + if (*path == NULL) { + ret = -1; + goto out; + } out: return ret; |