[Nagios-devel] SOLVED: Configfile parsing bug with single objects (Patch provided)

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] SOLVED: Configfile parsing bug with single objects (Patch provided)

Post by Guest »

--=_mixed 004FE9A1C1256F33_=
Content-Type: multipart/alternative; boundary="=_alternative 004FE9A1C1256F33_="


--=_alternative 004FE9A1C1256F33_=
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Greetings again,

I couldn't let loose and started researching the problem - and finally=20
found the bug ;)

Nagios does indeed have a bug in config-file parsing when NSCORE is=20
defined
(which is actually always true afaik) and there is only ONE single object=20
definition
of any object (host, hostgroup, servicegroup, command, etc...)
In the file common/objects.c the configs are read from the files, the=20
corresponding
objects created and added to the linked lists.

At the end of each add=5F() function the adding to the=20
linked list is incorrectly
implemented.

Example from objects.c at the end of *add=5Fhost(...)
(this code is true for every *add=5F in objects.c - just=20
change the variable names)

#ifdef NSCORE
/* hosts are sorted alphabetically for daemon, so add new items to =

tail of list */
if(host=5Flist=3D=3DNULL){
host=5Flist=3Dnew=5Fhost;
host=5Flist=5Ftail=3Dhost=5Flist;
}
host=5Flist=5Ftail->next=3Dnew=5Fhost;
host=5Flist=5Ftail=3Dnew=5Fhost;
#else
/* hosts are sorted in reverse for CGIs, so add new items to head=20
of list */
new=5Fhost->next=3Dhost=5Flist;
host=5Flist=3Dnew=5Fhost;
#endif

What happens is the following:

1. host=5Flist is NULL since it's the first entry the parser found so far.
2. host=5Flist and host=5Flist=5Ftail get initialized with the newly create=
d=20
object new=5Fhost, correct so far.

But since the host=5Flist just got initialiased the next steps don't make=20
sense at all:
(remember new=5Fhost and host=5Flist are identical for the first parsed=20
object!)

3. new=5Fhost->next become host=5Flist (aka. new=5Fhost)
4 host=5Flist (aka new=5Fhost) becomes new=5Fhost.

Therefor host=5Flist->next points to host=5Flist again now.
Voila, here we got the loop.
host=5Flist->next gets correctly overwritten when a second object is added =

and
everything is fine, but if you only have a single definition of any kind=20
of object -> BOOM!

I provided a patch to fix the problem, encasing the last 2 statements in=20
an else {} statement, so
they don't get executed when the list just got initialised.

have fun and merge it quickly ;)

sash


--------------------------------------------------
Sascha Runschke
Netzwerk Administration
IT-Services

ABIT AG
Robert-Bosch-Str. 1
40668 Meerbusch

Tel.:+49 (0) 2150.9153.226
mailto:[email protected]

http://www.abit.net
http://www.abit-epos.net
http://www.my-academy.net
--------------------------------------------------
Der Inhalt dieser Email sowie die Anh=E4nge sind ausschlie=DFlich f=FCr den=
=20
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat=20
dieser Email oder dessen Vertreter sein sollten, so beachten Sie bitte,=20
da=DF jede Form der Kenntnisnahme, Ver=F6ffentlichung, Vervielf=E4ltigung =
oder=20
Weitergabe des Inhalts dieser Email unzul=E4ssig ist. Wir m=F6chten Sie=20
au=DFerdem darauf hinweisen, da=DF die Kommunikation per Email =FCber das=20
Internet unsicher ist, da fuer unberechtigte Dritte grunds=E4tzlich die=20
M=F6glichkeit der Kenntnisnahme und Manipulation besteht. Wenn Sie diese=20
Nachricht versehentlich erhalten, informieren Sie bitte den Absender und=20
l=F6schen diese Nachricht mit den Anh=E4ngen. Herzlichen Dank

The information and any attachments contained in this email are intended=20
solely for the addressee. Access to this email by anyone else is=20
unauthorized. If you are not the intended recipient, any form of=20
disclosure, reproduction, distribution or any action taken or refrained=20
from in reliance on it, is prohibited and may be unlawful. We also like to =

inform you that communication via email over the internet is insecure=20
because third parties may have the possibility to access and manipulate=20
emails. If you have received the message in error, please advise the=20
sender and delete the message and any attachme

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked