Buffer lengths and fgets()

Mike Benoit mikeb at netnation.com
Fri Sep 5 18:07:59 CEST 2003


Yes, we ran in to this exact same "long config line" issue. It would be
really nice to get this fixed in the main tree. 

On Thu, 2003-09-04 at 13:51, Adam J. Kunen wrote:
> Hello nagios-devel people,
> 
> 	We use Nagios-1.1 here in the Comp Sci deptartment of the UW to monitor all of our hosts and printers (roughly 1000 hosts). And recently we ran into a problem with the core nagios code, specifically the config file parsing code.
> 
> 	We use the text file system for our configs  and we ran into a problem one day after adding a small cluster (48 nodes).  After going thru the code I found the problem to be in "xdata/xodtemplace.c".  Specifically in xodtemplate_read_config_data and fgets().   The problem was that one of our config lines got larger than MAX_XODTEMPLATE_INPUT_BUFFER.  However this was not detected as a problem, since fgets() reads to an end-of-line or until it fills up the buffer... however the nagios code is written to assume that fgets() always returns a complete line.  
> 
> 	In our case, we have a define {} block which defines the hostgroup for all of the machines that we have on our second floor.  The 'members' line contains 8797 bytes (yeah its long, but this floor is our main platform).  So the parser would only get the first MAX_XODTEMPLATE_INPUT_BUFFER bytes (8196) and assume that it was a complete '\n' terminated line.  Then it thought the next line was the remainder of the same line... and not recognize that it didn't read a complete line!  So our new cluster just pushed that line over the buffer length.
> 	
> 	For our site, I modified the code.  I wrote a wrapper around fgets, and eliminated the need for the fixed input buffer lengths. I know I could have just increased the max buffer lenght, but that seemed like more of a band-aid instead of a real fix.
> 
> 	I would really like to get this update out to the nagios-devel people because I think that it is a good improvemnt. (i don't claim that its the best resolution for the problem).  I was wondering what the best way to do this is?  I looked at the faq about posting diff's,  but since I added two files 'common/fvgets.c' and 'common/fvgets.h', I wasn't sure how i would post those...
> 
> 	Also, I ran into some trouble when I was troubleshooting our problem because when the CGI's all failed due to our 'long config line' they reported authentication problems (which threw me for a loop :).  And it seems that if there is any config file error, the CGI's just assume it is an auth problem... I really don't know how to correct this, but it would be nice if they could give some errors like the nagios daemon does (which didn't give the right error either, but reported what config file (and line) that the problem occured at).
> 
> Thanks.
-- 
Best Regards,
 
Mike Benoit
NetNation Communications Inc.
Systems Engineer
Tel: 604-684-6892 or 888-983-6600
 ---------------------------------------
 
 Disclaimer: Opinions expressed here are my own and not 
 necessarily those of my employer



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf




More information about the Developers mailing list