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

Report from  bauerm at pestilenz dot org.
With help from and ok millert@
This commit is contained in:
matthieu
2022-11-11 13:56:12 +00:00
parent 317ccbdd41
commit fd3c33bec8

View File

@@ -160,7 +160,14 @@ 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);
if (cmdname) {
if (argv == NULL || argv[0] == NULL) {
*cmdname = strdup("");
return;
} else
*cmdname = strdup(argv[0]); *cmdname = strdup(argv[0]);
}
if (cmdargs) {
i = 1; i = 1;
while (argv[i] != NULL) { while (argv[i] != NULL) {
len += strlen(argv[i]) + 1; len += strlen(argv[i]) + 1;
@@ -169,10 +176,11 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
*cmdargs = calloc(1, len); *cmdargs = calloc(1, len);
i = 1; i = 1;
while (argv[i] != NULL) { while (argv[i] != NULL) {
strlcat(*cmdargs, argv[i], len); strlcat(*(char **)cmdargs, argv[i], len);
strlcat(*cmdargs, " ", len); strlcat(*(char **)cmdargs, " ", len);
i++; i++;
} }
}
kvm_close(kd); kvm_close(kd);
} }
#else /* Linux using /proc/pid/cmdline */ #else /* Linux using /proc/pid/cmdline */