summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@herrb.eu>2022-11-11 14:58:02 +0100
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-10-22 21:07:14 +0000
commit5f9cac4c34e6212e3e4fc22ff4c182d6013eeafc (patch)
tree43ad0223d942942ba060de3e624a2c3819fd428e
parent9d310679476abb150b8b9055ad44132ffbfa0e3b (diff)
Don't crash if the client argv or argv[0] is NULL.
Report from bauerm at pestilenz dot org. (cherry picked from commit a8512146ba9f475a384a35337f51c7730ba7b4ce) Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1719>
-rw-r--r--os/client.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/os/client.c b/os/client.c
index 922172cc5..2ed69ea4c 100644
--- a/os/client.c
+++ b/os/client.c
@@ -268,18 +268,26 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
if (n != 1)
return;
argv = kvm_getargv(kd, kp, 0);
- *cmdname = strdup(argv[0]);
- i = 1;
- while (argv[i] != NULL) {
- len += strlen(argv[i]) + 1;
- i++;
+ if (cmdname) {
+ if (argv == NULL || argv[0] == NULL) {
+ *cmdname = strdup("");
+ return;
+ } else
+ *cmdname = strdup(argv[0]);
}
- *cmdargs = calloc(1, len);
- i = 1;
- while (argv[i] != NULL) {
- strlcat(*cmdargs, argv[i], len);
- strlcat(*cmdargs, " ", len);
- i++;
+ if (cmdargs) {
+ i = 1;
+ while (argv[i] != NULL) {
+ len += strlen(argv[i]) + 1;
+ 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);
}