Prevent potential leak of kp.
This commit is contained in:
parent
fd3fcfd09e
commit
7d7a720b05
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.226 2019/05/13 19:28:27 ajacoutot Exp $
|
||||
# $OpenBSD: Makefile,v 1.227 2019/05/14 14:46:34 ajacoutot Exp $
|
||||
|
||||
# Everything is a Freaking GLib/GTK+ problem
|
||||
CFLAGS += -g
|
||||
@ -13,7 +13,7 @@ GNOME_PROJECT= gtk+
|
||||
PKGNAME-main= gtk+2-${GNOME_VERSION}
|
||||
PKGNAME-cups= gtk+2-cups-${GNOME_VERSION}
|
||||
|
||||
REVISION-main= 3
|
||||
REVISION-main= 4
|
||||
REVISION-cups= 1
|
||||
|
||||
CATEGORIES= x11 devel
|
||||
|
@ -1,4 +1,6 @@
|
||||
$OpenBSD: patch-gtk_gtkmountoperation-x11_c,v 1.3 2019/05/13 19:28:27 ajacoutot Exp $
|
||||
$OpenBSD: patch-gtk_gtkmountoperation-x11_c,v 1.4 2019/05/14 14:46:34 ajacoutot Exp $
|
||||
|
||||
https://gitlab.gnome.org/GNOME/gtk/merge_requests/844
|
||||
|
||||
From 0334ea1c889331adb02d361670e24b3f85b5b0d6 Mon Sep 17 00:00:00 2001
|
||||
From: Antoine Jacoutot <ajacoutot@gnome.org>
|
||||
@ -43,7 +45,7 @@ Index: gtk/gtkmountoperation-x11.c
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
@@ -724,6 +721,103 @@ pid_get_command_line (GPid pid)
|
||||
@@ -724,6 +721,110 @@ pid_get_command_line (GPid pid)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
@ -57,23 +59,30 @@ Index: gtk/gtkmountoperation-x11.c
|
||||
+{
|
||||
+ struct kinfo_proc *kp;
|
||||
+ 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));
|
||||
+
|
||||
+ kp = g_malloc0 (len);
|
||||
+
|
||||
+ if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0)
|
||||
+ return -1;
|
||||
+ goto out;
|
||||
+
|
||||
+ ppid = kp->p_ppid;
|
||||
+
|
||||
+ g_free (kp);
|
||||
+out:
|
||||
+ if (kp)
|
||||
+ g_free (kp);
|
||||
+ return ppid;
|
||||
+}
|
||||
+
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.212 2019/05/13 20:37:41 robert Exp $
|
||||
# $OpenBSD: Makefile,v 1.213 2019/05/14 14:46:34 ajacoutot Exp $
|
||||
|
||||
# XXX add support for libcloudproviders?
|
||||
|
||||
@ -21,7 +21,7 @@ PKGNAME-cups= gtk+3-cups-${GNOME_VERSION}
|
||||
PKGNAME-cloudprint= gtk+3-cloudprint-${GNOME_VERSION}
|
||||
PKGNAME-guic= gtk-update-icon-cache-${GNOME_VERSION}
|
||||
|
||||
REVISION-main= 1
|
||||
REVISION-main= 2
|
||||
REVISION-cups= 0
|
||||
REVISION-cloudprint= 0
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
$OpenBSD: patch-gtk_gtkmountoperation-x11_c,v 1.14 2019/05/13 19:28:28 ajacoutot Exp $
|
||||
$OpenBSD: patch-gtk_gtkmountoperation-x11_c,v 1.15 2019/05/14 14:46:34 ajacoutot Exp $
|
||||
|
||||
https://gitlab.gnome.org/GNOME/gtk/merge_requests/844
|
||||
|
||||
From 0334ea1c889331adb02d361670e24b3f85b5b0d6 Mon Sep 17 00:00:00 2001
|
||||
From: Antoine Jacoutot <ajacoutot@gnome.org>
|
||||
@ -8,29 +10,42 @@ Subject: [PATCH] pid_get_parent: fix for OpenBSD
|
||||
Index: gtk/gtkmountoperation-x11.c
|
||||
--- gtk/gtkmountoperation-x11.c.orig
|
||||
+++ gtk/gtkmountoperation-x11.c
|
||||
@@ -720,7 +720,7 @@ pid_get_command_line (GPid pid)
|
||||
@@ -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;
|
||||
size_t len;
|
||||
GPid ppid;
|
||||
- GPid ppid;
|
||||
+ GPid ppid = 0;
|
||||
|
||||
@@ -731,11 +731,14 @@ pid_get_parent (GPid pid)
|
||||
return (-1);
|
||||
+ /* 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);
|
||||
+
|
||||
+ if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0)
|
||||
return -1;
|
||||
|
||||
- ppid = kp.p_ppid;
|
||||
+ ppid = kp->p_ppid;
|
||||
+ if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0)
|
||||
+ goto out;
|
||||
|
||||
+ g_free (kp);
|
||||
+ ppid = kp->p_ppid;
|
||||
+
|
||||
+out:
|
||||
+ if (kp)
|
||||
+ g_free (kp);
|
||||
return ppid;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.11 2019/05/13 21:04:44 ajacoutot Exp $
|
||||
# $OpenBSD: Makefile,v 1.12 2019/05/14 14:46:34 ajacoutot Exp $
|
||||
|
||||
# XXX: PORTROACH is set at the end of this file to override gnome.port.mk
|
||||
|
||||
@ -24,7 +24,7 @@ PKGNAME-cloudprint= gtk+4-cloudprint-${GNOME_VERSION}
|
||||
PKGNAME-guic= gtk4-update-icon-cache-${GNOME_VERSION}
|
||||
PKGNAME-media= gtk+4-media-${GNOME_VERSION}
|
||||
|
||||
REVISION-main= 1
|
||||
REVISION-main= 2
|
||||
|
||||
CATEGORIES= x11 devel
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
$OpenBSD: patch-gtk_gtkmountoperation-x11_c,v 1.1 2019/05/13 19:28:28 ajacoutot Exp $
|
||||
$OpenBSD: patch-gtk_gtkmountoperation-x11_c,v 1.2 2019/05/14 14:46:34 ajacoutot Exp $
|
||||
|
||||
https://gitlab.gnome.org/GNOME/gtk/merge_requests/844
|
||||
|
||||
From 0334ea1c889331adb02d361670e24b3f85b5b0d6 Mon Sep 17 00:00:00 2001
|
||||
From: Antoine Jacoutot <ajacoutot@gnome.org>
|
||||
@ -8,29 +10,42 @@ Subject: [PATCH] pid_get_parent: fix for OpenBSD
|
||||
Index: gtk/gtkmountoperation-x11.c
|
||||
--- gtk/gtkmountoperation-x11.c.orig
|
||||
+++ gtk/gtkmountoperation-x11.c
|
||||
@@ -736,7 +736,7 @@ pid_get_command_line (GPid pid)
|
||||
@@ -736,22 +736,32 @@ pid_get_command_line (GPid pid)
|
||||
static GPid
|
||||
pid_get_parent (GPid pid)
|
||||
{
|
||||
- struct kinfo_proc kp;
|
||||
+ struct kinfo_proc *kp;
|
||||
size_t len;
|
||||
GPid ppid;
|
||||
- GPid ppid;
|
||||
+ GPid ppid = 0;
|
||||
|
||||
@@ -747,11 +747,14 @@ pid_get_parent (GPid pid)
|
||||
return (-1);
|
||||
+ /* 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);
|
||||
+
|
||||
+ if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0)
|
||||
return -1;
|
||||
|
||||
- ppid = kp.p_ppid;
|
||||
+ ppid = kp->p_ppid;
|
||||
+ if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0)
|
||||
+ goto out;
|
||||
|
||||
+ g_free (kp);
|
||||
+ ppid = kp->p_ppid;
|
||||
+
|
||||
+out:
|
||||
+ if (kp)
|
||||
+ g_free (kp);
|
||||
return ppid;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user