Added missing check for fopen return value

This would have led to a crash when a NULL pointer would have been used as
a valid FILE handle.
This commit is contained in:
Markus Makela
2016-02-25 20:10:37 +02:00
parent 2c28d8c5de
commit 784166ad0b

View File

@ -1286,7 +1286,11 @@ static bool process_user_templates(FW_INSTANCE *instance, user_template_t *templ
*/
static bool process_rule_file(const char* filename, FW_INSTANCE* instance)
{
int rc = 1;
FILE *file = fopen(filename, "r");
if (file)
{
yyscan_t scanner;
struct parser_stack pstack;
@ -1301,7 +1305,7 @@ static bool process_rule_file(const char* filename, FW_INSTANCE* instance)
dbfw_yy_switch_to_buffer(buf, scanner);
/** Parse the rule file */
int rc = dbfw_yyparse(scanner);
rc = dbfw_yyparse(scanner);
dbfw_yy_delete_buffer(buf, scanner);
dbfw_yylex_destroy(scanner);
@ -1321,6 +1325,14 @@ static bool process_rule_file(const char* filename, FW_INSTANCE* instance)
free_user_templates(pstack.templates);
strlink_free(pstack.active_rules);
strlink_free(pstack.user);
}
else
{
char errbuf[STRERROR_BUFLEN];
MXS_ERROR("Failed to open rule file '%s': %d, %s", filename, errno,
strerror_r(errno, errbuf, sizeof(errbuf)));
}
return rc == 0;
}