d1681e
From dba81543259bbb4b590918477156dfb68812dd8a Mon Sep 17 00:00:00 2001
d1681e
From: Amar Tumballi <amarts@redhat.com>
d1681e
Date: Tue, 21 Aug 2018 19:33:08 +0530
d1681e
Subject: [PATCH 356/359] io-stats: sanitize the dump path further
d1681e
d1681e
In the previous patch, while addressing the comment on review,
d1681e
a "/" at the end of the "/var/run/gluster" directory was missed out.
d1681e
d1681e
Also noticed that the logic to convert the '/' to '-' for sanity
d1681e
of the path needed to change.
d1681e
d1681e
Testing: Ran the tests which marked the bug as FailedQA,
d1681e
and also validated the originally reported issue, and now we see
d1681e
a specific log when not so clean path is given as the value to
d1681e
this xattr.
d1681e
d1681e
BUG: 1605086
d1681e
Change-Id: Ia8397ecd5841a72d0daca0106557e1226c293e35
d1681e
Signed-off-by: Amar Tumballi <amarts@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/147644
d1681e
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
d1681e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
d1681e
Tested-by: Atin Mukherjee <amukherj@redhat.com>
d1681e
---
d1681e
 xlators/debug/io-stats/src/io-stats.c | 11 ++++++-----
d1681e
 1 file changed, 6 insertions(+), 5 deletions(-)
d1681e
d1681e
diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c
d1681e
index 868890f..16a11df 100644
d1681e
--- a/xlators/debug/io-stats/src/io-stats.c
d1681e
+++ b/xlators/debug/io-stats/src/io-stats.c
d1681e
@@ -3014,7 +3014,7 @@ conditional_dump (dict_t *dict, char *key, data_t *value, void *data)
d1681e
         char                 *filename = NULL;
d1681e
         FILE                 *logfp = NULL;
d1681e
         struct ios_dump_args args = {0};
d1681e
-        int                   pid, namelen;
d1681e
+        int                   pid, namelen, dirlen;
d1681e
         char                  dump_key[100];
d1681e
         char                 *slash_ptr = NULL;
d1681e
         char                 *path_in_value = NULL;
d1681e
@@ -3039,16 +3039,17 @@ conditional_dump (dict_t *dict, char *key, data_t *value, void *data)
d1681e
                         "%s: no \"../\" allowed in path", path_in_value);
d1681e
                 return -1;
d1681e
         }
d1681e
-        namelen = (strlen (IOS_STATS_DUMP_DIR) + value->len +
d1681e
-                   strlen (this->name) + 2);         /* '.' and '\0' */
d1681e
+        dirlen = strlen (IOS_STATS_DUMP_DIR);
d1681e
+        namelen = (dirlen + value->len + strlen (this->name) + 3);
d1681e
+        /* +3 for '/', '.' and '\0' added in snprintf below*/
d1681e
 
d1681e
         filename = alloca0 (namelen);
d1681e
 
d1681e
-        snprintf (filename, namelen, "%s%s.%s", IOS_STATS_DUMP_DIR,
d1681e
+        snprintf (filename, namelen, "%s/%s.%s", IOS_STATS_DUMP_DIR,
d1681e
                   path_in_value, this->name);
d1681e
 
d1681e
         /* convert any slashes to '-' so that fopen works correctly */
d1681e
-        slash_ptr = strchr (filename + value->len + 1, '/');
d1681e
+        slash_ptr = strchr (filename + dirlen + 1, '/');
d1681e
         while (slash_ptr) {
d1681e
                 *slash_ptr = '-';
d1681e
                 slash_ptr = strchr (slash_ptr, '/');
d1681e
-- 
d1681e
1.8.3.1
d1681e