summaryrefslogtreecommitdiffstats
path: root/recipes-extended/nagios/nagios-core/0001-fix-segment-fault.patch
blob: 1ea8da9c89996ad72102107101c7e29093f3f682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 65e4539c6eca215d8d79ef8acc5c8842b886752a Mon Sep 17 00:00:00 2001
From: Chen Qi <Qi.Chen@windriver.com>
Date: Mon, 3 Sep 2018 13:15:29 +0800
Subject: [PATCH] fix segment fault

When using strdup(dirname(cfgfile)) directly, we will have segment
fault. This happens at least for glibc 2.28. So we do it step by
step, and this would avoid the segment fault.

Upstream-Status: Pending

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 include/shared.h    | 1 +
 xdata/xodtemplate.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/shared.h b/include/shared.h
index 1dfa0c7..0188c7d 100644
--- a/include/shared.h
+++ b/include/shared.h
@@ -31,6 +31,7 @@
 #include <wchar.h>
 #include <locale.h>
 #include <limits.h>
+#include <libgen.h>
 
 #include <time.h>
 #include "lib/libnagios.h"
diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
index 33d51f4..da32e69 100644
--- a/xdata/xodtemplate.c
+++ b/xdata/xodtemplate.c
@@ -187,6 +187,7 @@ static void xodtemplate_free_template_skiplists(void) {
 int xodtemplate_read_config_data(const char *main_config_file, int options) {
 #ifdef NSCORE
 	char *cfgfile = NULL;
+	char *cfgfile_dir = NULL;
 	char *config_base_dir = NULL;
 	char *input = NULL;
 	char *var = NULL;
@@ -261,7 +262,8 @@ int xodtemplate_read_config_data(const char *main_config_file, int options) {
 			printf("Unable to allocate memory!\n");
 			return ERROR;
 			}
-		config_base_dir = (char *)strdup(dirname(cfgfile));
+		cfgfile_dir = dirname(cfgfile);
+		config_base_dir = (char *)strdup(cfgfile_dir);
 		my_free(cfgfile);
 
 		/* open the main config file for reading (we need to find all the config files to read) */
-- 
2.7.4