From 0b67f531ca2c0a632e3b2c12095fb005ff528fa8 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Wed, 9 Jun 2010 14:28:48 -0400 Subject: Fixing NULL dereferencing in ini_config Addressing ticket #504 --- common/ini/ini_config.c | 58 +++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c index bd8f88b2c..26d2d4cb9 100644 --- a/common/ini/ini_config.c +++ b/common/ini/ini_config.c @@ -364,20 +364,25 @@ static int ini_to_collection(FILE *file, break; case RET_ERROR: - pe.line = line; - pe.error = ext_err; - error = col_add_binary_property(*error_list, NULL, - ERROR_TXT, &pe, sizeof(pe)); - if (error) { - TRACE_ERROR_NUMBER("Failed to add error to collection", error); - fclose(file); - col_destroy_collection(current_section); - if (created) { - col_destroy_collection(*error_list); - *error_list = NULL; + /* Try to add to the error list only if it is present */ + if (error_list) { + pe.line = line; + pe.error = ext_err; + error = col_add_binary_property(*error_list, NULL, + ERROR_TXT, &pe, sizeof(pe)); + if (error) { + TRACE_ERROR_NUMBER("Failed to add error to collection", + error); + fclose(file); + col_destroy_collection(current_section); + if (created) { + col_destroy_collection(*error_list); + *error_list = NULL; + } + return error; } - return error; } + /* Exit if there was an error parsing file */ if (error_level != INI_STOP_ON_NONE) { TRACE_ERROR_STRING("Invalid format of the file", ""); @@ -389,20 +394,25 @@ static int ini_to_collection(FILE *file, case RET_INVALID: default: - pe.line = line; - pe.error = ext_err; - error = col_add_binary_property(*error_list, NULL, - WARNING_TXT, &pe, sizeof(pe)); - if (error) { - TRACE_ERROR_NUMBER("Failed to add warning to collection", error); - fclose(file); - col_destroy_collection(current_section); - if (created) { - col_destroy_collection(*error_list); - *error_list = NULL; + /* Try to add to the error list only if it is present */ + if (error_list) { + pe.line = line; + pe.error = ext_err; + error = col_add_binary_property(*error_list, NULL, + WARNING_TXT, &pe, sizeof(pe)); + if (error) { + TRACE_ERROR_NUMBER("Failed to add warning to collection", + error); + fclose(file); + col_destroy_collection(current_section); + if (created) { + col_destroy_collection(*error_list); + *error_list = NULL; + } + return error; } - return error; } + /* Exit if we are told to exit on warnings */ if (error_level == INI_STOP_ON_ANY) { TRACE_ERROR_STRING("Invalid format of the file", ""); -- cgit