Fix potential memory allocation failure crashes in config.c.

* Added required checks to the returned memory allocation pointers to
prevent crashes.

* Made ast_include_rename() create a replacement ast_variable list node if
the new filename is longer than the available space.  Fixes potential
crash and memory leak.

* Factored out ast_variable_move() from ast_variable_update() so
ast_include_rename() can also use it when creating a replacement
ast_variable list node.

* Made the filename stuffed at the end of the struct a minimum allocated
size in ast_variable_new() in case ast_include_rename() changes the stored
filename.

* Constify struct char pointers pointing to strings stuffed at the end of
the struct for: ast_variable, cache_file_mtime, and ast_config_map.

* Factored out cfmtime_new() to remove inlined code and allow some struct
pointers to become const.

* Removed the list lock from struct cache_file_mtime that was never used.

* Added doxygen comments to several structure elements and better
documented what strings are stuffed at the struct end char array.

* Reworked ast_config_text_file_save() and set_fn() to handle allocation
failure of the include file scratch pad object tracking blank lines.

* Made ast_config_text_file_save() fn[] declared with PATH_MAX to ensure
it is long enough for any filename with path.  Also reduced the number of
container fileset buckets from a rediculus 180,000 to 1023.

JIRA AST-618

Review: https://reviewboard.asterisk.org/r/1378/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@334296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2011-09-02 17:10:58 +00:00
parent b178214e07
commit 6d49117675
2 changed files with 350 additions and 162 deletions

View File

@@ -73,11 +73,16 @@ typedef enum {
/*! \brief Structure for variables, used for configurations and for channel variables */
struct ast_variable {
/*! Variable name. Stored in stuff[] at struct end. */
const char *name;
/*! Variable value. Stored in stuff[] at struct end. */
const char *value;
/*! Next node in the list. */
struct ast_variable *next;
char *file;
/*! Filename where variable found. Stored in stuff[] at struct end. */
const char *file;
int lineno;
int object; /*!< 0 for variable, 1 for object */
@@ -85,6 +90,10 @@ struct ast_variable {
struct ast_comment *precomments;
struct ast_comment *sameline;
struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */
/*!
* \brief Contents of file, name, and value in that order stuffed here.
* \note File must be stuffed before name because of ast_include_rename().
*/
char stuff[0];
};