From 65e4539c6eca215d8d79ef8acc5c8842b886752a Mon Sep 17 00:00:00 2001 From: Chen Qi 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 --- 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 #include #include +#include #include #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