Skip to content

Commit 626dc56

Browse files
committed
Exit gracefully in case of corrupted filters (Closes issue Ettercap#782)
1 parent 2da6c13 commit 626dc56

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Diff for: utils/etterfilter/ef_compiler.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ size_t compile_tree(struct filter_op **fop)
239239
struct filter_op *array = NULL;
240240
struct unfold_elm *ue;
241241

242-
BUG_IF(tree_root == NULL);
242+
// invalid file
243+
if (tree_root == NULL)
244+
return 0;
243245

244246
fprintf(stdout, " Unfolding the meta-tree ");
245247
fflush(stdout);

Diff for: utils/etterfilter/ef_main.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct ef_globals *ef_gbls;
4141

4242
int main(int argc, char *argv[])
4343
{
44+
int ret_value = 0;
4445
libettercap_init();
4546
ef_globals_alloc();
4647
select_text_interface();
@@ -88,8 +89,12 @@ int main(int argc, char *argv[])
8889
fprintf(stdout, "\n\nThe script contains errors...\n\n");
8990

9091
/* write to file */
91-
if (write_output() != E_SUCCESS)
92-
FATAL_ERROR("Cannot write output file (%s)", EF_GBL_OPTIONS->output_file);
92+
ret_value = write_output();
93+
if (ret_value == -E_NOTHANDLED)
94+
FATAL_ERROR("Cannot write output file (%s): the filter is not correctly handled.", EF_GBL_OPTIONS->output_file);
95+
else if (ret_value == -E_INVALID)
96+
FATAL_ERROR("Cannot write output file (%s): the filter format is not correct. ", EF_GBL_OPTIONS->output_file);
97+
9398
ef_globals_free();
9499
return 0;
95100
}

Diff for: utils/etterfilter/ef_output.c

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ int write_output(void)
5151
if (fop == NULL)
5252
return -E_NOTHANDLED;
5353

54+
if (ninst == 0)
55+
return -E_INVALID;
56+
5457
/* create the file */
5558
fd = open(EF_GBL_OPTIONS->output_file, O_CREAT | O_RDWR | O_TRUNC | O_BINARY, 0644);
5659
ON_ERROR(fd, -1, "Can't create file %s", EF_GBL_OPTIONS->output_file);

0 commit comments

Comments
 (0)