os/log: handle NULL string argument in vpnprintf

Since this function is called from signal handlers (e.g. OsSigHandler
processing SIGSEGV/SIGBUS), a NULL %s argument triggers a recursive fault.

Assisted-by: Claude:claude-claude-opus-4-6
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2200>
This commit is contained in:
Peter Hutterer 2026-04-17 10:12:31 +10:00 committed by Marge Bot
parent c38037b11e
commit 75541aa42b

View file

@ -418,7 +418,7 @@ vpnprintf(char *string, int size_in, const char *f, va_list args)
int f_idx = 0;
int s_idx = 0;
int f_len = strlen_sigsafe(f);
char *string_arg;
const char *string_arg;
char number[21];
int p_len;
int i;
@ -474,6 +474,8 @@ vpnprintf(char *string, int size_in, const char *f, va_list args)
switch (f[f_idx]) {
case 's':
string_arg = va_arg(args, char*);
if (!string_arg)
string_arg = "(null)";
for (i = 0; string_arg[i] != 0 && s_idx < size - 1 && s_idx < precision; i++)
string[s_idx++] = string_arg[i];