1 --- a/driver/xscreensaver.c
2 +++ b/driver/xscreensaver.c
5 #define MAX(x,y)((x)>(y)?(x):(y))
7 +/* Define the default wrapper prefix here, for NixOS */
8 +#define NIXOS_WRAPPER_PREFIX "@wrapperPrefix@"
10 /* Globals used in this file.
12 @@ -632,12 +634,24 @@ handle_sigchld (Display *dpy, Bool blanked_p)
14 hack_environment (void)
16 + static const char *wrapper_path = NIXOS_WRAPPER_PREFIX;
17 static const char *def_path = DEFAULT_PATH_PREFIX;
18 const char *opath = getenv("PATH");
20 if (! opath) opath = "/bin:/usr/bin"; /* WTF */
21 - npath = (char *) malloc(strlen(def_path) + strlen(opath) + 20);
22 + /* NOTE: The NixOS patch adds extra margin than what would be expected for a
23 + single extra ":" PATH separator to account for UTF-32 encoding. The
24 + original 20 bytes would have only accounted for UTF-16 safely (the path
25 + concatenation would have needed 28 bytes of margin at minimum for UTF-32).
27 + npath = (char *) malloc(strlen(wrapper_path) + strlen(def_path) + strlen(opath) + 32);
28 strcpy (npath, "PATH=");
29 + if (wrapper_path && *wrapper_path)
31 + strcat (npath, wrapper_path);
32 + strcat (npath, ":");
35 strcat (npath, def_path);
37 strcat (npath, opath);