]> Kevux Git Server - fll/commitdiff
Security: Add missing parameter checks and rename "data" to "custom".
authorKevin Day <thekevinday@gmail.com>
Fri, 13 May 2022 00:11:24 +0000 (19:11 -0500)
committerKevin Day <thekevinday@gmail.com>
Fri, 13 May 2022 00:11:24 +0000 (19:11 -0500)
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
level_2/fll_program/c/program.h

index 3b41cfc88913ed8c1910c9313b59e07b17a72c1e..e537e01c9d73751ce3dd326cda5a5933b8ff63ef 100644 (file)
@@ -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);
     }
 
index 6c30ed5a1c7af606835ba53a85de819b52a34249..234a9002618694cd42574308cb758d1bfdd314f6 100644 (file)
@@ -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()
  */