Blame SOURCES/0001-sadc-Fix-segfault-that-may-happen-when-appending-dat.patch

e626d6
From c2b36aa61e333e2492ced8beaa84f6f19b8cf6ed Mon Sep 17 00:00:00 2001
e626d6
From: Sebastien GODARD <sysstat@users.noreply.github.com>
e626d6
Date: Sat, 30 Dec 2017 11:16:32 +0100
e626d6
Subject: [PATCH] sadc: Fix segfault that may happen when appending data to
e626d6
 file
e626d6
e626d6
Buffers need to be allocated according to activities present in file so
e626d6
that we can append data to that file.
e626d6
e626d6
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
e626d6
e626d6
(cherry-picked from commit 1cf6596368da94ac48656dbb117f4e8c0cde58b9)
e626d6
---
e626d6
 sadc.c | 29 +++++++++++++++--------------
e626d6
 1 file changed, 15 insertions(+), 14 deletions(-)
e626d6
e626d6
diff --git a/sadc.c b/sadc.c
e626d6
index 53e9175..fa94d1f 100644
e626d6
--- a/sadc.c
e626d6
+++ b/sadc.c
e626d6
@@ -824,20 +824,21 @@ void open_ofile(int *ofd, char ofile[])
e626d6
 			for (i = 0; i < file_hdr.sa_nr_act; i++) {
e626d6
 				
e626d6
 				p = get_activity_position(act, file_act[i].id);
e626d6
-				
e626d6
-				if ((act[p]->nr != file_act[i].nr) || (act[p]->nr2 != file_act[i].nr2)) {
e626d6
-					/*
e626d6
-					 * Force number of items (serial lines, network interfaces...)
e626d6
-					 * and sub-items to that of the file, and reallocate structures.
e626d6
-					 */
e626d6
-					act[p]->nr  = file_act[i].nr;
e626d6
-					act[p]->nr2 = file_act[i].nr2;
e626d6
-					SREALLOC(act[p]->_buf0, void, act[p]->msize * act[p]->nr * act[p]->nr2);
e626d6
-				}
e626d6
-				
e626d6
-				/* Save activity sequence */
e626d6
-				id_seq[i] = file_act[i].id;
e626d6
-				act[p]->options |= AO_COLLECTED;
e626d6
+
e626d6
+                                act[p]->nr = file_act[i].nr;
e626d6
+                                /*
e626d6
+                                 * Force number of sub-items to that of the file, and reallocate structures.
e626d6
+                                 * Note: Structures have been allocated in sa_sys_init() only for activities
e626d6
+                                 * that are collected. But since activities from file now prevail over them,
e626d6
+                                 * we need to reallocate.
e626d6
+                                 */
e626d6
+                                act[p]->nr2 = file_act[i].nr2;
e626d6
+                                SREALLOC(act[p]->_buf0, void,
e626d6
+                                         (size_t) act[p]->msize * (size_t) act[p]->nr * (size_t) act[p]->nr2);
e626d6
+
e626d6
+                                /* Save activity sequence */
e626d6
+                                id_seq[i] = file_act[i].id;
e626d6
+                                act[p]->options |= AO_COLLECTED;
e626d6
 			}
e626d6
 		}
e626d6
 	}
e626d6
-- 
e626d6
2.21.0
e626d6