[Nagiosplug-devel] Segmentation fault (int pos) in check_procs

Thomas Guyot-Sionnest dermoth at aei.ca
Mon Aug 23 13:46:01 CEST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10-08-10 12:16 PM, Баталов Григорий wrote:
> Hello!
> I've found the clause in nagios-plugins-1.4.15/plugins/check_procs.c:
> 
> int pos; /* number of spaces before 'args' in `ps` output */
> ...
> if ( cols >= expected_cols ) {
>    resultsum = 0;
>    asprintf (&procargs, "%s", input_line + pos);
>    strip (procargs);
> ...
> 
> So I wonder how this variable (pos) is supposed to be initialized.
> On my system (tinycore linux 3.0) it gives different huge numbers
> like 166949407, 166949462, etc. and corresponding asprintf segfaults.
> Should I explicitly initialize it with "int pos=0;" or something?

This variable should be initialized by a scanf call using the macros
PS_FORMAT and PS_VARLIST - this is system-specific. From my config.h (In
the root of the source code, this file is generated by configure) I have
the following definitions:

/* Format string for scanning ps output in check_procs */
#define PS_FORMAT "%s %d %d %d %d %d %f %s %n"

/* Whether the ps utility uses the "procetime" field */
/* #undef PS_USES_PROCETIME */

/* Variable list for sscanf of 'ps' output */
#define PS_VARLIST
procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procprog,&pos


And then in check_procs.c the variables are populated with:

    cols = sscanf (input_line, PS_FORMAT, PS_VARLIST);

I have very little experience with sscanf, but I guess either the
PS_FORMAT was wrong based on your ps command (detected by configure), or
you manually specified a broken --with-ps-varlist option to configure.


Could you please send the PS_* macros in config.h, and run the
check_procs command in full debug mode (with -vvv) and send us the
output (as an attachment, to avoid line-wraps in email)?

Thank you,

- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxyX3AACgkQ6dZ+Kt5BchZ8uACeMSAl5qQHJQPPB9zKOsM27E/V
0N4AmwSxMF9WAx7gUUB7WCmQ9DfrwQRK
=A8HR
-----END PGP SIGNATURE-----




More information about the Devel mailing list