From 4cd040bced85ac462169c45e84ede49606f0e32f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 31 Mar 2019 22:14:03 +0100 Subject: [PATCH] uxpty.c: stop setting DISPLAY to "(null)". In some contexts (namely pterm on a pure Wayland system, and Uppity), seat_get_x_display() will return NULL. In that situation uxpty.c was cheerfully passing it to dupprintf regardless, which in principle is undefined behaviour and in practice was causing it to construct the silly environment string "DISPLAY=(null)". Now we handle that case by unsetenv("DISPLAY") instead. --- unix/uxpty.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/unix/uxpty.c b/unix/uxpty.c index 0c7e820c..2f182b43 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1113,9 +1113,13 @@ Backend *pty_backend_create( * on. */ const char *x_display = seat_get_x_display(pty->seat); - char *x_display_env_var = dupprintf("DISPLAY=%s", x_display); - putenv(x_display_env_var); - /* As above, we don't free this. */ + if (x_display) { + char *x_display_env_var = dupprintf("DISPLAY=%s", x_display); + putenv(x_display_env_var); + /* As above, we don't free this. */ + } else { + unsetenv("DISPLAY"); + } } #endif {