summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvar <post@0x21.biz>2026-01-19 00:00:00 +0000
committerGitHub <noreply@github.com>2026-01-19 01:00:00 +0100
commitbccb38dc9d56ca5cecce8f2f9a988ec5d31626db (patch)
tree43640c3d956c3c7564eb894cf3e49f0b731eabab
parentf5f60f57172a4157b90415746a0f1a87c46c0bd9 (diff)
downloadmonitoring-plugins-bccb38dc9d56ca5cecce8f2f9a988ec5d31626db.tar.gz
check_icmp: Populate progname before np_extra_opts call (#2226)HEADmastercoverity/master
Within np_extra_opts, the ini parser expects a valid progname as the default section to select a configuration section in the ini file. However, within the check_icmp codebase, the progname is being populated directly after the np_extra_opts call, being a null pointer before. $ ./check_icmp --extra-opts=@foo.ini Segmentation fault (core dumped) > #0 strlen () at /usr/src/lib/libc/arch/amd64/string/strlen.S:125 > #1 0x000003989615d032 in _libc_strdup (str=Variable "str" is not available.) at /usr/src/lib/libc/string/strdup.c:44 > #2 0x000003966f751b74 in np_get_defaults (locator=0x73ede1e538ea "@foo.ini", default_section=0x0) at parse_ini.c:91 > #3 0x000003966f7518ce in np_extra_opts (argc=0x73ede1e5369c, argv=0x73ede1e53728, plugin_name=0x0) at extra_opts.c:98 > #4 0x000003966f74165a in main (argc=1, argv=0x0) at check_icmp.c:832 The progname variable is set within the process_arguments function, requiring the already enriched arguments from np_extra_opts. Thus, I moved the progname detection out of this function, directly before the np_extra_opts call. This pattern does already exists in check_tcp. I briefly looked for similar issues in other plugins, but found none.
-rw-r--r--plugins-root/check_icmp.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 5bfb5cb5..e536e31c 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -277,15 +277,6 @@ typedef struct {
277 check_icmp_config config; 277 check_icmp_config config;
278} check_icmp_config_wrapper; 278} check_icmp_config_wrapper;
279check_icmp_config_wrapper process_arguments(int argc, char **argv) { 279check_icmp_config_wrapper process_arguments(int argc, char **argv) {
280 /* get calling name the old-fashioned way for portability instead
281 * of relying on the glibc-ism __progname */
282 char *ptr = strrchr(argv[0], '/');
283 if (ptr) {
284 progname = &ptr[1];
285 } else {
286 progname = argv[0];
287 }
288
289 check_icmp_config_wrapper result = { 280 check_icmp_config_wrapper result = {
290 .errorcode = OK, 281 .errorcode = OK,
291 .config = check_icmp_config_init(), 282 .config = check_icmp_config_init(),
@@ -828,6 +819,14 @@ int main(int argc, char **argv) {
828 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */ 819 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */
829 environ = NULL; 820 environ = NULL;
830 821
822 /* determine program- and service-name quickly */
823 progname = strrchr(argv[0], '/');
824 if (progname != NULL) {
825 progname++;
826 } else {
827 progname = argv[0];
828 }
829
831 /* Parse extra opts if any */ 830 /* Parse extra opts if any */
832 argv = np_extra_opts(&argc, argv, progname); 831 argv = np_extra_opts(&argc, argv, progname);
833 832