1 From 0390d827eab62ad2d84f0d6db8278d683659c0ba Mon Sep 17 00:00:00 2001
2 From: Oleg Pereverzev <oleg.pereverzev@gmail.com>
3 Date: Mon, 12 Jun 2017 23:20:59 +0300
4 Subject: [PATCH] Support for GCC 7
8 lib/snprintf.c | 6 ++++++
9 src/naemon/checks.c | 12 +++++++++++-
10 src/naemon/configuration.c | 13 +++++++++++--
11 src/naemon/macros.c | 18 ++++++++++++++++++
12 src/naemon/xodtemplate.c | 11 ++++++++++-
13 6 files changed, 59 insertions(+), 4 deletions(-)
15 diff --git a/lib/runcmd.c b/lib/runcmd.c
16 index eb6668fe..4e55fbd7 100644
19 @@ -199,6 +199,9 @@ int runcmd_cmd2strv(const char *str, int *out_argc, char **out_argv)
20 set_state(STATE_INSQ | STATE_INARG);
24 + __attribute__((fallthrough));
27 if (have_state(STATE_INSQ))
29 diff --git a/lib/snprintf.c b/lib/snprintf.c
30 index 49bf8962..80b69dbf 100644
33 @@ -493,6 +493,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
36 cnk->flags |= DP_F_UP;
38 + __attribute__((fallthrough));
42 cnk->flags |= DP_F_UNSIGNED;
43 @@ -503,6 +506,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
46 cnk->flags |= DP_F_UP;
48 + __attribute__((fallthrough));
51 /* hex float not supported yet */
53 diff --git a/src/naemon/checks.c b/src/naemon/checks.c
54 index 97bd9f73..91d83ef1 100644
55 --- a/src/naemon/checks.c
56 +++ b/src/naemon/checks.c
57 @@ -207,6 +207,9 @@ int process_check_result_queue(char *dirname)
58 char *temp_buffer = NULL;
59 int result = OK, check_result_files = 0;
62 + unsigned int writesize;
65 /* make sure we have what we need */
66 if (dirname == NULL) {
67 @@ -240,9 +243,16 @@ int process_check_result_queue(char *dirname)
70 /* create /path/to/file */
73 + writesize = snprintf(file, sizeof(file), "%s/%s", dirname, dirfile->d_name);
74 + if (writesize < (strlen(dirname) + strlen(dirfile->d_name) + 2))
75 + nm_log(NSLOG_RUNTIME_WARNING, "Warning: truncated path to file in check result queue directory '%s'", dirfile->d_name);
77 snprintf(file, sizeof(file), "%s/%s", dirname, dirfile->d_name);
79 file[sizeof(file) - 1] = '\x0';
82 /* process this if it's a check result file... */
83 x = strlen(dirfile->d_name);
84 if (x == 7 && dirfile->d_name[0] == 'c') {
85 diff --git a/src/naemon/configuration.c b/src/naemon/configuration.c
86 index a2a8d3ed..c4dc97dd 100644
87 --- a/src/naemon/configuration.c
88 +++ b/src/naemon/configuration.c
89 @@ -59,6 +59,9 @@ read_config_file(const char *main_config_file, nagios_macros *mac)
91 mmapfile *thefile = NULL;
94 + unsigned int writesize;
97 /* open the config file for reading */
98 if ((thefile = mmap_fopen(main_config_file)) == NULL) {
99 @@ -1021,10 +1024,16 @@ read_config_file(const char *main_config_file, nagios_macros *mac)
100 if (strcmp(dirfile->d_name + strlen(dirfile->d_name) - 4, ".cfg"))
103 - /* create /path/to/file */
104 + /* create /path/to/file */
106 + writesize = snprintf(file, sizeof(file), "%s/%s", include_dir, dirfile->d_name);
107 + if (writesize < (strlen(include_dir) + strlen(dirfile->d_name) + 2))
108 + nm_log(NSLOG_RUNTIME_WARNING, "Warning: truncated path to sub-configuration file '%s'", dirfile->d_name);
110 snprintf(file, sizeof(file), "%s/%s", include_dir, dirfile->d_name);
112 file[sizeof(file) - 1] = '\x0';
115 error |= read_config_file(file, mac);
118 diff --git a/src/naemon/macros.c b/src/naemon/macros.c
119 index 700bc821..13d817cf 100644
120 --- a/src/naemon/macros.c
121 +++ b/src/naemon/macros.c
122 @@ -1518,6 +1518,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
124 case MACRO_HOSTGROUPNAMES:
127 + __attribute__((fallthrough));
130 case MACRO_HOSTALIAS:
131 case MACRO_HOSTADDRESS:
132 @@ -1612,6 +1615,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
133 /********************/
134 case MACRO_HOSTGROUPMEMBERS:
137 + __attribute__((fallthrough));
139 case MACRO_HOSTGROUPNAME:
140 case MACRO_HOSTGROUPALIAS:
141 case MACRO_HOSTGROUPNOTES:
142 @@ -1640,6 +1646,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
144 case MACRO_SERVICEGROUPNAMES:
147 + __attribute__((fallthrough));
149 case MACRO_SERVICEDESC:
150 case MACRO_SERVICESTATE:
151 case MACRO_SERVICESTATEID:
152 @@ -1757,6 +1766,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
153 case MACRO_SERVICEGROUPNOTESURL:
154 case MACRO_SERVICEGROUPACTIONURL:
157 + __attribute__((fallthrough));
159 case MACRO_SERVICEGROUPNAME:
160 case MACRO_SERVICEGROUPALIAS:
161 /* a standard servicegroup macro */
162 @@ -1781,6 +1793,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
164 case MACRO_CONTACTGROUPNAMES:
167 + __attribute__((fallthrough));
169 case MACRO_CONTACTNAME:
170 case MACRO_CONTACTALIAS:
171 case MACRO_CONTACTEMAIL:
172 @@ -1841,6 +1856,9 @@ static int grab_macrox_value_r(nagios_macros *mac, int macro_type, char *arg1, c
173 /***********************/
174 case MACRO_CONTACTGROUPMEMBERS:
177 + __attribute__((fallthrough));
179 case MACRO_CONTACTGROUPNAME:
180 case MACRO_CONTACTGROUPALIAS:
181 /* a standard contactgroup macro */
182 diff --git a/src/naemon/xodtemplate.c b/src/naemon/xodtemplate.c
183 index d5fd1cda..225fc40a 100644
184 --- a/src/naemon/xodtemplate.c
185 +++ b/src/naemon/xodtemplate.c
186 @@ -8443,7 +8443,10 @@ static int xodtemplate_process_config_dir(char *dir_name)
189 struct stat stat_buf;
192 + unsigned int writesize;
195 if (verify_config >= 2)
196 printf("Processing object config directory '%s'...\n", dir_name);
198 @@ -8462,7 +8465,13 @@ static int xodtemplate_process_config_dir(char *dir_name)
201 /* create /path/to/file */
203 + writesize = snprintf(file, sizeof(file), "%s/%s", dir_name, dirfile->d_name);
204 + if (writesize < (strlen(dir_name) + strlen(dirfile->d_name) + 2))
205 + nm_log(NSLOG_RUNTIME_WARNING, "Warning: truncated path to file '%s' in config directory '%s'", dirfile->d_name, dir_name);
207 snprintf(file, sizeof(file), "%s/%s", dir_name, dirfile->d_name);
209 file[sizeof(file) - 1] = '\x0';
211 /* process this if it's a non-hidden config file... */