Skip to content
Permalink
Browse files Browse the repository at this point in the history
Exit gracefully in case of corrupted filters (Closes issue Ettercap#782)
  • Loading branch information
LocutusOfBorg committed Feb 9, 2017
1 parent 2da6c13 commit 626dc56
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion utils/etterfilter/ef_compiler.c
Expand Up @@ -239,7 +239,9 @@ size_t compile_tree(struct filter_op **fop)
struct filter_op *array = NULL;
struct unfold_elm *ue;

BUG_IF(tree_root == NULL);
// invalid file
if (tree_root == NULL)
return 0;

fprintf(stdout, " Unfolding the meta-tree ");
fflush(stdout);
Expand Down
9 changes: 7 additions & 2 deletions utils/etterfilter/ef_main.c
Expand Up @@ -41,6 +41,7 @@ struct ef_globals *ef_gbls;

int main(int argc, char *argv[])
{
int ret_value = 0;
libettercap_init();
ef_globals_alloc();
select_text_interface();
Expand Down Expand Up @@ -88,8 +89,12 @@ int main(int argc, char *argv[])
fprintf(stdout, "\n\nThe script contains errors...\n\n");

/* write to file */
if (write_output() != E_SUCCESS)
FATAL_ERROR("Cannot write output file (%s)", EF_GBL_OPTIONS->output_file);
ret_value = write_output();
if (ret_value == -E_NOTHANDLED)
FATAL_ERROR("Cannot write output file (%s): the filter is not correctly handled.", EF_GBL_OPTIONS->output_file);
else if (ret_value == -E_INVALID)
FATAL_ERROR("Cannot write output file (%s): the filter format is not correct. ", EF_GBL_OPTIONS->output_file);

ef_globals_free();
return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions utils/etterfilter/ef_output.c
Expand Up @@ -51,6 +51,9 @@ int write_output(void)
if (fop == NULL)
return -E_NOTHANDLED;

if (ninst == 0)
return -E_INVALID;

/* create the file */
fd = open(EF_GBL_OPTIONS->output_file, O_CREAT | O_RDWR | O_TRUNC | O_BINARY, 0644);
ON_ERROR(fd, -1, "Can't create file %s", EF_GBL_OPTIONS->output_file);
Expand Down

0 comments on commit 626dc56

Please sign in to comment.