d1681e
From 69e6933898a37ef7c929b2d4b5561e5e3a407be4 Mon Sep 17 00:00:00 2001
d1681e
From: Mohammed Rafi KC <rkavunga@redhat.com>
d1681e
Date: Thu, 16 Aug 2018 17:04:22 +0530
d1681e
Subject: [PATCH 353/359] snapshot/handshake: store description after strdup
d1681e
d1681e
problem:
d1681e
During a handshake, when we import a friend data
d1681e
snap description variable was just referenced to
d1681e
dictionary value.
d1681e
d1681e
Solution:
d1681e
snap description should have a separate memory allocated
d1681e
through gf_strdup
d1681e
d1681e
>Change-Id: I94da0c57919e1228919231d1563a001362b100b8
d1681e
>fixes: bz#1618004
d1681e
>Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
d1681e
d1681e
upstream patch: https://review.gluster.org/#/c/glusterfs/+/20747/
d1681e
d1681e
Change-Id: I94da0c57919e1228919231d1563a001362b100b8
d1681e
BUG: 1615578
d1681e
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/147521
d1681e
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d1681e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
d1681e
---
d1681e
 ...-1618004-fix-memory-corruption-in-snap-import.t | 48 ++++++++++++++++++++++
d1681e
 .../mgmt/glusterd/src/glusterd-snapshot-utils.c    | 17 ++++++--
d1681e
 2 files changed, 62 insertions(+), 3 deletions(-)
d1681e
 create mode 100644 tests/bugs/snapshot/bug-1618004-fix-memory-corruption-in-snap-import.t
d1681e
d1681e
diff --git a/tests/bugs/snapshot/bug-1618004-fix-memory-corruption-in-snap-import.t b/tests/bugs/snapshot/bug-1618004-fix-memory-corruption-in-snap-import.t
d1681e
new file mode 100644
d1681e
index 0000000..a2c004e
d1681e
--- /dev/null
d1681e
+++ b/tests/bugs/snapshot/bug-1618004-fix-memory-corruption-in-snap-import.t
d1681e
@@ -0,0 +1,48 @@
d1681e
+#!/bin/bash
d1681e
+
d1681e
+. $(dirname $0)/../../include.rc
d1681e
+. $(dirname $0)/../../volume.rc
d1681e
+. $(dirname $0)/../../snapshot.rc
d1681e
+. $(dirname $0)/../../cluster.rc
d1681e
+
d1681e
+function get_volume_info ()
d1681e
+{
d1681e
+        local var=$1
d1681e
+        $CLI_1 volume info $V0 | grep "^$var" | sed 's/.*: //'
d1681e
+}
d1681e
+
d1681e
+cleanup;
d1681e
+
d1681e
+TEST verify_lvm_version
d1681e
+TEST launch_cluster 2
d1681e
+TEST setup_lvm 2
d1681e
+
d1681e
+TEST $CLI_1 peer probe $H2;
d1681e
+EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count;
d1681e
+
d1681e
+TEST $CLI_1 volume create $V0 $H1:$L1 $H2:$L2
d1681e
+EXPECT "$V0" get_volume_info 'Volume Name';
d1681e
+EXPECT 'Created' get_volume_info 'Status';
d1681e
+
d1681e
+TEST $CLI_1 volume start $V0
d1681e
+EXPECT 'Started' get_volume_info 'Status';
d1681e
+
d1681e
+
d1681e
+# Setting system limit
d1681e
+TEST $CLI_1 snapshot config activate-on-create enable
d1681e
+
d1681e
+TEST $CLI_1 snapshot create snap1 $V0 no-timestamp description "test"
d1681e
+TEST kill_glusterd 1
d1681e
+#deactivate snapshot for changing snap version, so that handshake will
d1681e
+#happen when glusterd is restarted
d1681e
+TEST $CLI_2 snapshot deactivate snap1
d1681e
+TEST start_glusterd 1
d1681e
+
d1681e
+#Wait till handshake complete
d1681e
+EXPECT_WITHIN ${PROCESS_UP_TIMEOUT} 'Stopped' snapshot_status snap1
d1681e
+
d1681e
+#Delete the snapshot, without this fix, delete will lead to assertion failure
d1681e
+$CLI_1 snapshot delete all
d1681e
+EXPECT '0' get_snap_count CLI_1;
d1681e
+cleanup;
d1681e
+
d1681e
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
d1681e
index ad206f6..48cf326 100644
d1681e
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
d1681e
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
d1681e
@@ -766,7 +766,7 @@ glusterd_add_snap_to_dict (glusterd_snap_t *snap, dict_t *peer_data,
d1681e
         }
d1681e
 
d1681e
         if (snap->description) {
d1681e
-                snprintf (buf, sizeof(buf), "%s.snapid", prefix);
d1681e
+                snprintf (buf, sizeof(buf), "%s.description", prefix);
d1681e
                 ret = dict_set_dynstr_with_alloc (peer_data, buf,
d1681e
                                                   snap->description);
d1681e
                 if (ret) {
d1681e
@@ -1551,6 +1551,7 @@ glusterd_import_friend_snap (dict_t *peer_data, int32_t snap_count,
d1681e
 {
d1681e
         char                 buf[NAME_MAX]    = "";
d1681e
         char                 prefix[NAME_MAX] = "";
d1681e
+        char                *description      = NULL;
d1681e
         dict_t              *dict             = NULL;
d1681e
         glusterd_snap_t     *snap             = NULL;
d1681e
         glusterd_volinfo_t  *snap_vol         = NULL;
d1681e
@@ -1590,8 +1591,18 @@ glusterd_import_friend_snap (dict_t *peer_data, int32_t snap_count,
d1681e
         strncpy (snap->snapname, peer_snap_name, sizeof (snap->snapname) - 1);
d1681e
         gf_uuid_parse (peer_snap_id, snap->snap_id);
d1681e
 
d1681e
-        snprintf (buf, sizeof(buf), "%s.snapid", prefix);
d1681e
-        ret = dict_get_str (peer_data, buf, &snap->description);
d1681e
+        snprintf (buf, sizeof(buf), "%s.description", prefix);
d1681e
+        ret = dict_get_str (peer_data, buf, &description);
d1681e
+        if (ret == 0 && description) {
d1681e
+                snap->description = gf_strdup (description);
d1681e
+                if (snap->description == NULL) {
d1681e
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
d1681e
+                                GD_MSG_SNAP_CREATION_FAIL,
d1681e
+                                "Saving the Snapshot Description Failed");
d1681e
+                        ret = -1;
d1681e
+                        goto out;
d1681e
+                }
d1681e
+        }
d1681e
 
d1681e
         snprintf (buf, sizeof(buf), "%s.time_stamp", prefix);
d1681e
         ret = dict_get_int64 (peer_data, buf, &snap->time_stamp);
d1681e
-- 
d1681e
1.8.3.1
d1681e