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.
This commit is contained in:
CTCaer 2021-10-01 14:27:57 +03:00
parent e31d6446db
commit 99d15eaac8

View file

@ -4712,9 +4712,9 @@ DWORD *f_expand_cltbl (
} }
if (f_lseek(fp, CREATE_LINKMAP)) { /* Create cluster link table */ if (f_lseek(fp, CREATE_LINKMAP)) { /* Create cluster link table */
ff_memfree(fp->cltbl); ff_memfree(fp->cltbl);
fp->cltbl = NULL; fp->cltbl = (void *)0;
EFSPRINTF("CLTBLSZ"); EFSPRINTF("CLTBLSZ");
return NULL; return (void *)0;
} }
f_lseek(fp, 0); f_lseek(fp, 0);
@ -6737,6 +6737,8 @@ int f_puts (
putbuff pb; putbuff pb;
if (str == (void *)0) return EOF; /* String is NULL */
putc_init(&pb, fp); putc_init(&pb, fp);
while (*str) putc_bfd(&pb, *str++); /* Put the string */ while (*str) putc_bfd(&pb, *str++); /* Put the string */
return putc_flush(&pb); return putc_flush(&pb);
@ -6763,6 +6765,8 @@ int f_printf (
TCHAR c, d, str[32], *p; TCHAR c, d, str[32], *p;
if (fmt == (void *)0) return EOF; /* String is NULL */
putc_init(&pb, fp); putc_init(&pb, fp);
va_start(arp, fmt); va_start(arp, fmt);