From 99d15eaac8310e8bc5dd21afdd0dbceacfcd134b Mon Sep 17 00:00:00 2001 From: CTCaer Date: Fri, 1 Oct 2021 14:27:57 +0300 Subject: [PATCH] bdk: fatfs: check if string is null for puts/printf Avoid writing garbage to a file by checking string pointer passed to f_puts and f_printf. Important on many embedded platforms that do not abort on NULL dereference. --- bdk/libs/fatfs/ff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bdk/libs/fatfs/ff.c b/bdk/libs/fatfs/ff.c index 75e0271..ebef0f9 100644 --- a/bdk/libs/fatfs/ff.c +++ b/bdk/libs/fatfs/ff.c @@ -4712,9 +4712,9 @@ DWORD *f_expand_cltbl ( } if (f_lseek(fp, CREATE_LINKMAP)) { /* Create cluster link table */ ff_memfree(fp->cltbl); - fp->cltbl = NULL; + fp->cltbl = (void *)0; EFSPRINTF("CLTBLSZ"); - return NULL; + return (void *)0; } f_lseek(fp, 0); @@ -6737,6 +6737,8 @@ int f_puts ( putbuff pb; + if (str == (void *)0) return EOF; /* String is NULL */ + putc_init(&pb, fp); while (*str) putc_bfd(&pb, *str++); /* Put the string */ return putc_flush(&pb); @@ -6763,6 +6765,8 @@ int f_printf ( TCHAR c, d, str[32], *p; + if (fmt == (void *)0) return EOF; /* String is NULL */ + putc_init(&pb, fp); va_start(arp, fmt);