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

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