52 lines
1.4 KiB
Text
52 lines
1.4 KiB
Text
From 7d8be1c1ffc31523e2de09d4829169b78dd391e4 Mon Sep 17 00:00:00 2001
|
|
From: Antoine Jacoutot <ajacoutot@openbsd.org>
|
|
Date: Fri, 17 May 2019 11:55:16 +0000
|
|
Subject: [PATCH] pid_get_parent: fix potential leak of kp
|
|
|
|
From 0334ea1c889331adb02d361670e24b3f85b5b0d6 Mon Sep 17 00:00:00 2001
|
|
From: Antoine Jacoutot <ajacoutot@gnome.org>
|
|
Date: Mon, 13 May 2019 20:47:46 +0200
|
|
Subject: [PATCH] pid_get_parent: fix for OpenBSD
|
|
|
|
Index: gtk/gtkmountoperation-x11.c
|
|
--- gtk/gtkmountoperation-x11.c.orig
|
|
+++ gtk/gtkmountoperation-x11.c
|
|
@@ -720,22 +720,32 @@ pid_get_command_line (GPid pid)
|
|
static GPid
|
|
pid_get_parent (GPid pid)
|
|
{
|
|
- struct kinfo_proc kp;
|
|
+ struct kinfo_proc *kp = NULL;
|
|
size_t len;
|
|
- GPid ppid;
|
|
+ GPid ppid = 0;
|
|
|
|
+ /* fail if trying to get the parent of the init process (no such thing) */
|
|
+ if (pid == 1)
|
|
+ goto out;
|
|
+
|
|
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid,
|
|
sizeof(struct kinfo_proc), 0 };
|
|
|
|
if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
|
|
- return (-1);
|
|
+ goto out;
|
|
+
|
|
mib[5] = (len / sizeof(struct kinfo_proc));
|
|
|
|
- if (sysctl (mib, G_N_ELEMENTS (mib), &kp, &len, NULL, 0) < 0)
|
|
- return -1;
|
|
+ kp = g_malloc0 (len);
|
|
|
|
- ppid = kp.p_ppid;
|
|
+ if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0)
|
|
+ goto out;
|
|
|
|
+ ppid = kp->p_ppid;
|
|
+
|
|
+out:
|
|
+ if (kp)
|
|
+ g_free (kp);
|
|
return ppid;
|
|
}
|
|
|