[Nagiosplug-devel] Segfault in check_ping (need help fixing)

Thomas Guyot-Sionnest dermoth at aei.ca
Tue Apr 24 06:28:00 CEST 2007

Yesterday I assisted sb in a Nagios upgrade and the newer version of
check_ping was segfaulting.

It happens in a strlen done internally by asprintf on line 128. My guess
is that something passed to asprintf is not initialized properly but I'm
not sure which one. The guilty line is:

  asprintf (&cmd, rawcmd, timeout_interval, max_packets, addresses[i]);
# else

My two guesses are:

1) cmd == NULL. In some plugins I saw things such as
  output = strdup ("");
  asprintf (&output, ...

Is this the RightThing(tm) to do? Could it be the cause?

2) mallos/realloc's
  char **addresses = NULL;
  addresses = malloc (sizeof(char*) * max_addr);
  addresses = realloc (addresses, sizeof(char*) * max_addr);

I understand the concept of malloc/realloc but when it comes to fancy
sizes I always get lost in pointers. Anyone skilled enough could verify
that these alloc enough memory?

Since I cannot reproduce the segfault I can't test it, and the user
reporting this left.

More details here:



More information about the Devel mailing list