Skip to content

Commit c989414

Browse files
jackson-cooperdstgloorious
authored andcommitted
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> (cherry picked from commit 3e369bd) Signed-off-by: Stefan Gloor <stefan.gloor@siemens.com>
1 parent 9b079f7 commit c989414

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/tfm_vprintf/src/tfm_vprintf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ static void output_str(tfm_log_output_str output_func, void *priv, const char *s
5959
{
6060
const char *str_ptr = str;
6161

62+
if (str_ptr == NULL) {
63+
assert(false);
64+
return;
65+
}
66+
6267
if (calculate_length) {
6368
len = 0;
6469
while (*str_ptr++ != '\0') {

0 commit comments

Comments
 (0)