summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2016-07-19 11:33:19 +0530
committerAravinda VK <avishwan@redhat.com>2016-08-25 00:30:53 -0700
commitc9434a70f07ec25821563f66f36767c3a7ad0de4 (patch)
tree2cec6ee26a14935d1b62618cbaf4be63f5766e63
parent9df752213e6f8a1cc9a5e875cf68ca8ef32f61db (diff)
glusterd/geo-rep: Add relative path validation to copy file command
Added validation for input file, command fails if input file path is relative path pointing outside of GLUSTERD_WORKDIR. BUG: 1350784 Change-Id: I329d43ebed69bfe9fe03d6be70dc8c78a605ffc5 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/14772 Reviewed-on: http://review.gluster.org/14948 NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> Smoke: Gluster Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Kotresh HR <khiremat@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-geo-rep.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
index 123fdc11655..428d75652fa 100644
--- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
+++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c
@@ -2402,6 +2402,9 @@ glusterd_op_stage_copy_file (dict_t *dict, char **op_errstr)
glusterd_conf_t *priv = NULL;
struct stat stbuf = {0,};
xlator_t *this = NULL;
+ char workdir[PATH_MAX] = {0,};
+ char realpath_filename[PATH_MAX] = {0,};
+ char realpath_workdir[PATH_MAX] = {0,};
this = THIS;
GF_ASSERT (this);
@@ -2446,6 +2449,37 @@ glusterd_op_stage_copy_file (dict_t *dict, char **op_errstr)
snprintf (abs_filename, sizeof(abs_filename),
"%s/%s", priv->workdir, filename);
+ if (!realpath (priv->workdir, realpath_workdir)) {
+ snprintf (errmsg, sizeof (errmsg), "Failed to get "
+ "realpath of %s: %s", priv->workdir,
+ strerror (errno));
+ *op_errstr = gf_strdup (errmsg);
+ ret = -1;
+ goto out;
+ }
+
+ if (!realpath (abs_filename, realpath_filename)) {
+ snprintf (errmsg, sizeof (errmsg), "Failed to get "
+ "realpath of %s: %s", filename,
+ strerror (errno));
+ *op_errstr = gf_strdup (errmsg);
+ ret = -1;
+ goto out;
+ }
+
+ /* Add Trailing slash to workdir, without slash strncmp
+ will succeed for /var/lib/glusterd_bad */
+ snprintf (workdir, sizeof(workdir), "%s/", realpath_workdir);
+
+ /* Protect against file copy outside $workdir */
+ if (strncmp (workdir, realpath_filename, strlen (workdir))) {
+ snprintf (errmsg, sizeof (errmsg), "Source file"
+ " is outside of %s directory", priv->workdir);
+ *op_errstr = gf_strdup (errmsg);
+ ret = -1;
+ goto out;
+ }
+
ret = lstat (abs_filename, &stbuf);
if (ret) {
snprintf (errmsg, sizeof (errmsg), "Source file"