From 98e28b71b2a7053365d713ddfecabedb65f5fc75 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Fri, 1 Nov 2019 06:54:07 +0000 Subject: [PATCH] loader: asprinf does crash arm64 due to missing NULL pointer check PCHAR macro needs to check if d is NULL. MFC after: 3 days --- stand/libsa/printf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stand/libsa/printf.c b/stand/libsa/printf.c index a522c2c3e71f..1602a2dc519d 100644 --- a/stand/libsa/printf.c +++ b/stand/libsa/printf.c @@ -247,7 +247,17 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) static int kvprintf(char const *fmt, kvprintf_fn_t *func, void *arg, int radix, va_list ap) { -#define PCHAR(c) {int cc=(c); if (func) (*func)(cc, arg); else *d++ = cc; retval++; } +#define PCHAR(c) { \ + int cc = (c); \ + \ + if (func) { \ + (*func)(cc, arg); \ + } else if (d != NULL) { \ + *d++ = cc; \ + } \ + retval++; \ + } + char nbuf[MAXNBUF]; char *d; const char *p, *percent, *q;