summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-handle.c
diff options
context:
space:
mode:
authorNithya Balachandran <nbalacha@redhat.com>2014-12-17 13:58:56 +0530
committerRaghavendra Bhat <raghavendra@redhat.com>2015-02-18 22:55:08 -0800
commitf1c4ce0e220a46b7a43c9303c0d137498d421101 (patch)
treec710507701ad74105e74d0345a4349cd4b9ea740 /xlators/storage/posix/src/posix-handle.c
parent692dd7e83cc8a1c85581dda3f752d5ea3b184f8c (diff)
Storage/posix : Adding error checks in path formation
Renaming directories can cause the size of the buffer required for posix_handle_path to increase between the first call, which calculates the size, and the second call which forms the path in the buffer allocated based on the size calculated in the first call. The path created in the second call overflows the allocated buffer and overwrites the stack causing the brick process to crash. The fix adds a buffer size check to prevent the buffer overflow. It also checks and returns an error if the posix_handle_path call is unable to form the path instead of working on the incomplete path, which is likely to cause subsequent calls using the path to fail with ELOOP. Preventing buffer overflow and handling errors BUG: 1113960 Change-Id: If3d3c1952e297ad14f121f05f90a35baf42923aa Signed-off-by: Nithya Balachandran <nbalacha@redhat.com> Reviewed-on: http://review.gluster.org/9289 Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix-handle.c')
-rw-r--r--xlators/storage/posix/src/posix-handle.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c
index 7ab6543..5d184d9 100644
--- a/xlators/storage/posix/src/posix-handle.c
+++ b/xlators/storage/posix/src/posix-handle.c
@@ -296,8 +296,12 @@ posix_handle_pump (xlator_t *this, char *buf, int len, int maxlen,
blen = link_len - 48;
- if(len + blen >= maxlen)
+ if (len + blen >= maxlen) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Unable to form handle path for %s (maxlen = %d)",
+ buf, maxlen);
goto err;
+ }
memmove (buf + base_len + blen, buf + base_len,
(strlen (buf) - base_len) + 1);
@@ -371,11 +375,11 @@ posix_handle_path (xlator_t *this, uuid_t gfid, const char *basename,
errno = 0;
ret = posix_handle_pump (this, buf, len, maxlen,
base_str, base_len, pfx_len);
+ len = ret;
+
if (ret == -1)
break;
- len = ret;
-
ret = lstat (buf, &stat);
} while ((ret == -1) && errno == ELOOP);
@@ -841,13 +845,18 @@ posix_handle_unset (xlator_t *this, uuid_t gfid, const char *basename)
struct iatt stat;
char *path = NULL;
-
if (!basename) {
ret = posix_handle_unset_gfid (this, gfid);
return ret;
}
MAKE_HANDLE_PATH (path, this, gfid, basename);
+ if (!path) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Failed to create handle path for %s (%s)",
+ basename, uuid_utoa(gfid));
+ return -1;
+ }
ret = posix_istat (this, gfid, basename, &stat);
@@ -872,6 +881,12 @@ posix_create_link_if_gfid_exists (xlator_t *this, uuid_t gfid,
char *newpath = NULL;
MAKE_HANDLE_PATH (newpath, this, gfid, NULL);
+ if (!newpath) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Failed to create handle path (%s)", uuid_utoa(gfid));
+ return ret;
+ }
+
ret = lstat (newpath, &stbuf);
if (!ret) {
ret = sys_link (newpath, real_path);