LIB: Fix potential NULL pointer dereference
In tfm_vprintf.c, if the calculate_length flag is set and the string
passed to output_str is NULL, then the program would dereference the
NULL pointer as per the following warning:
warning: potential null pointer dereference [-Wnull-dereference]
64 | while (*str_ptr++ != '\0') {
| ^~~~~~~~~~
Fix this by adding an assertion that the string is non-NULL and
returning from the function in the case of release builds.
Change-Id: Ibc9fe50a19c8255298ea69b22770f8a255ad9266
Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com>
diff --git a/lib/tfm_vprintf/src/tfm_vprintf.c b/lib/tfm_vprintf/src/tfm_vprintf.c
index 654039d..ef10bc0 100644
--- a/lib/tfm_vprintf/src/tfm_vprintf.c
+++ b/lib/tfm_vprintf/src/tfm_vprintf.c
@@ -59,6 +59,11 @@
{
const char *str_ptr = str;
+ if (str_ptr == NULL) {
+ assert(false);
+ return;
+ }
+
if (calculate_length) {
len = 0;
while (*str_ptr++ != '\0') {