]> Kevux Git Server - fll/commitdiff
Security: safely print f_dynamic_string 0.4
authorKevin Day <thekevinday@gmail.com>
Fri, 30 Aug 2019 01:53:34 +0000 (20:53 -0500)
committerKevin Day <thekevinday@gmail.com>
Fri, 30 Aug 2019 01:53:34 +0000 (20:53 -0500)
The f_dynamic_string is not NULL terminated and should never be directly passed to a function that assumes strings are NULL terminated.

level_1/fl_colors/c/colors.c
level_1/fl_colors/c/colors.h
level_1/fl_colors/data/build/dependencies
level_1/fl_colors/data/build/settings

index 64e7524..1fef707 100644 (file)
@@ -123,7 +123,9 @@ extern "C"{
     #endif // _di_level_1_parameter_checking_
 
     if (start_color.used != 0) {
-      fprintf(file, "%s", start_color.string);
+      f_status status = f_print_dynamic_string(file, start_color);
+
+      if (f_error_is_error(status)) return status;
     }
 
     va_list ap;
@@ -135,7 +137,9 @@ extern "C"{
     va_end(ap);
 
     if (end_color.used != 0) {
-      fprintf(file, "%s", end_color.string);
+      f_status status = f_print_dynamic_string(file, end_color);
+
+      if (f_error_is_error(status)) return status;
     }
 
     return f_none;
@@ -150,7 +154,9 @@ extern "C"{
     #endif // _di_level_1_parameter_checking_
 
     if (start_color.used != 0) {
-      fprintf(file, "%s", start_color.string);
+      f_status status = f_print_dynamic_string(file, start_color);
+
+      if (f_error_is_error(status)) return status;
     }
 
     va_list ap;
@@ -162,7 +168,9 @@ extern "C"{
     va_end(ap);
 
     if (end_color.used != 0) {
-      fprintf(file, "%s", end_color.string);
+      f_status status = f_print_dynamic_string(file, end_color);
+
+      if (f_error_is_error(status)) return status;
     }
 
     // now print the trailing newline, this is done _after_ ending the colors to avoid color wrapping issues that can happen when a color code follows a newline
@@ -175,7 +183,9 @@ extern "C"{
 #ifndef _di_fl_print_color_code_
   f_return_status fl_print_color_code(f_file_type file, const f_dynamic_string color) {
     if (color.used != 0) {
-      fprintf(file, "%s", color.string);
+      f_status status = f_print_dynamic_string(file, color);
+
+      if (f_error_is_error(status)) return status;
     }
 
     return f_none;
index bcd3635..bdf0754 100644 (file)
@@ -21,6 +21,7 @@
 #include <level_0/strings.h>
 #include <level_0/file.h>
 #include <level_0/colors.h>
+#include <level_0/print.h>
 
 #ifdef __cplusplus
 extern "C"{
index e236478..93cf481 100644 (file)
@@ -10,7 +10,7 @@ version_micro 3
 build_compiler gcc
 build_linker ar
 build_libraries -lc
-build_libraries_fll -lf_memory -lf_file
+build_libraries_fll -lf_memory -lf_file -lf_print
 build_sources_library colors.c
 build_sources_program
 build_sources_headers colors.h