Don't crash if the client argv or argv[0] is NULL.

Report from  bauerm at pestilenz dot org.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/995>
This commit is contained in:
Matthieu Herrb 2022-11-11 14:58:02 +01:00 committed by Enrico Weigelt, metux IT consult
parent 0676cee63a
commit 9f7845ae22

View File

@ -327,18 +327,26 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
if (n != 1) if (n != 1)
return; return;
argv = kvm_getargv(kd, kp, 0); argv = kvm_getargv(kd, kp, 0);
*cmdname = strdup(argv[0]); if (cmdname) {
i = 1; if (argv == NULL || argv[0] == NULL) {
while (argv[i] != NULL) { *cmdname = strdup("");
len += strlen(argv[i]) + 1; return;
i++; } else
*cmdname = strdup(argv[0]);
} }
*cmdargs = calloc(1, len); if (cmdargs) {
i = 1; i = 1;
while (argv[i] != NULL) { while (argv[i] != NULL) {
strlcat(*cmdargs, argv[i], len); len += strlen(argv[i]) + 1;
strlcat(*cmdargs, " ", len); i++;
i++; }
*cmdargs = calloc(1, len);
i = 1;
while (argv[i] != NULL) {
strlcat(*(char **)cmdargs, argv[i], len);
strlcat(*(char **)cmdargs, " ", len);
i++;
}
} }
kvm_close(kd); kvm_close(kd);
} }