Bug#307218: Found how but not necessarily why

Brooks R Robinson extremescholar at gmail.com
Wed Nov 16 23:08:13 UTC 2005


Greetings,
	I found how this bug happens, but not necessarily why.  In asterisk.c of version 
1.0.7.dfsg (part of the quit_handler), here is some of the code:

538:	char filename[80] = "";

581:	if (option_console || option_remote) {
582:		if (getenv("HOME"))
583:		snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
584:			if (!ast_strlen_zero(filename))
585:				ast_el_write_history(filename);

	We also need this snip of code from include/asterisk/utils.h:

19:	static inline int ast_strlen_zero(const char *s)
20:	{
21:		return (*s == '\0');
22:	}

	So, somehow, there is an environment variable for HOME, but it is not what is expected.  It's 
either NULL, zero length, or "/".  So, we get *something* from line 582, and we pass into 583.  
this line writes out a filename to the character array.  Line 584 just makes sure that there is 
actaully something in the string (non-zero length), which in this case will always work as long as 
line 583 works.  Probably not the best check here.  Line 585 write the file.

	A value of "" or a value or "/" for the HOME environment will write this guy out to the 
root directory.  My guess is that somehow the HOME environment gets hosified on restart.  Maybe 
this will spark some other ideas...

HTH,

Brooks





More information about the Pkg-voip-maintainers mailing list