From aaee50502e1f131f03ef471d021226b4bbe65375 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 12 May 2022 19:11:24 -0500 Subject: [PATCH] Security: Add missing parameter checks and rename "data" to "custom". Using "data" as the variable name for the "custom" property is confusing and can lead to mistakes. Use "custom" to directly match that this is the "custom" property rather than the "data" property. --- level_2/fll_program/c/program.c | 15 +++++++++++---- level_2/fll_program/c/program.h | 6 +++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index 3b41cfc..e537e01 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -290,6 +290,10 @@ extern "C" { #ifndef _di_fll_program_standard_setdown_ f_status_t fll_program_standard_setdown(f_signal_t * const signal) { + #ifndef _di_level_2_parameter_checking_ + if (!signal) return F_status_set_error(F_parameter); + #endif // _di_level_2_parameter_checking_ + // Flush output pipes before closing. fflush(F_type_output_d); @@ -310,6 +314,9 @@ extern "C" { #ifndef _di_fll_program_standard_setup_ f_status_t fll_program_standard_setup(f_signal_t * const signal) { + #ifndef _di_level_2_parameter_checking_ + if (!signal) return F_status_set_error(F_parameter); + #endif // _di_level_2_parameter_checking_ f_signal_set_empty(&signal->set); f_signal_set_add(F_signal_abort, &signal->set); @@ -340,7 +347,7 @@ extern "C" { #ifndef _di_fll_program_standard_signal_received_ f_status_t fll_program_standard_signal_received(fll_program_data_t * const main) { - if (main->signal.id == -1) { + if (!main || main->signal.id == -1) { return F_false; } @@ -377,11 +384,11 @@ extern "C" { return F_interrupt_not; } - fll_program_data_t *data = (fll_program_data_t *) state_ptr->custom; + fll_program_data_t *custom = (fll_program_data_t *) state_ptr->custom; - data->signal_received = fll_program_standard_signal_received(data); + custom->signal_received = fll_program_standard_signal_received(custom); - if (data->signal_received == F_signal_abort || data->signal_received == F_signal_broken_pipe || data->signal_received == F_signal_hangup || data->signal_received == F_signal_interrupt || data->signal_received == F_signal_quit || data->signal_received == F_signal_termination) { + if (custom->signal_received == F_signal_abort || custom->signal_received == F_signal_broken_pipe || custom->signal_received == F_signal_hangup || custom->signal_received == F_signal_interrupt || custom->signal_received == F_signal_quit || custom->signal_received == F_signal_termination) { return F_status_set_error(F_interrupt); } diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index 6c30ed5..234a900 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -390,6 +390,8 @@ extern "C" { * @return * F_none on success. * + * F_parameter (with error bit) if a parameter is invalid. + * * Errors (with error bit) from: f_signal_close(). * * @see f_signal_close() @@ -410,6 +412,8 @@ extern "C" { * @return * F_none on success. * + * F_parameter (with error bit) if a parameter is invalid. + * * Errors (with error bit) from: f_signal_mask(). * Errors (with error bit) from: f_signal_open(). * @@ -433,7 +437,7 @@ extern "C" { * * @return * A positive number representing a valid signal on signal received. - * F_false on no signal received. + * F_false on no signal received or when main is NULL. * * @see f_signal_read() */ -- 1.8.3.1