SOLVED: Configfile parsing bug with single objects (Patch provided)

Sascha Runschke srunschke at abit.de
Wed Oct 20 16:32:53 CEST 2004


Greetings again,

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

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

At the end of each add_<some-structure>() function the adding to the 
linked list is incorrectly
implemented.

Example from objects.c  at the end of *add_host(...)
(this code is true for every *add_<some-structure> in objects.c - just 
change the variable names)

#ifdef NSCORE
        /* hosts are sorted alphabetically for daemon, so add new items to 
tail of list */
        if(host_list==NULL){
                host_list=new_host;
                host_list_tail=host_list;
                }
        host_list_tail->next=new_host;
        host_list_tail=new_host;
#else
        /* hosts are sorted in reverse for CGIs, so add new items to head 
of list */
        new_host->next=host_list;
        host_list=new_host;
#endif

What happens is the following:

1. host_list is NULL since it's the first entry the parser found so far.
2. host_list and host_list_tail get initialized with the newly created 
object new_host, correct so far.

But since the host_list just got initialiased the next steps don't make 
sense at all:
(remember new_host and host_list are identical for the first parsed 
object!)

3. new_host->next become host_list (aka. new_host)
4 host_list (aka new_host) becomes new_host.

Therefor host_list->next points to host_list again now.
Voila, here we got the loop.
host_list->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 
of object -> BOOM!

I provided a patch to fix the problem, encasing the last 2 statements in 
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:SRunschke at abit.de

http://www.abit.net
http://www.abit-epos.net
http://www.my-academy.net
--------------------------------------------------
Der Inhalt dieser Email sowie die Anhänge sind ausschließlich für den 
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat 
dieser Email oder dessen Vertreter sein sollten, so beachten Sie bitte, 
daß jede Form der Kenntnisnahme, Veröffentlichung,  Vervielfältigung oder 
Weitergabe des Inhalts dieser Email unzulässig ist. Wir möchten Sie 
außerdem darauf hinweisen, daß die Kommunikation per Email über das 
Internet unsicher ist, da fuer unberechtigte Dritte grundsätzlich die 
Möglichkeit der Kenntnisnahme und Manipulation besteht. Wenn Sie diese 
Nachricht versehentlich erhalten, informieren Sie bitte den Absender und 
löschen diese Nachricht mit den Anhängen. Herzlichen Dank

The information and any attachments contained in this email are intended 
solely for the addressee. Access to this email by anyone else is 
unauthorized. If you are not the intended recipient, any form of 
disclosure, reproduction, distribution or any action taken or refrained 
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 
because third parties may have the possibility to access and manipulate 
emails. If you have received the message in error, please advise the 
sender and delete the message and any attachments. Thank you very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20041020/530642c5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: objects.c.patch
Type: application/octet-stream
Size: 6412 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20041020/530642c5/attachment.obj>


More information about the Developers mailing list