From 39f3aa2ab66755ba25315449b5f8c59bd748b99d Mon Sep 17 00:00:00 2001 From: bch Date: Sat, 18 Feb 2017 21:12:30 +0000 Subject: [PATCH] add pledge support and error messages --- xmem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/xmem.c b/xmem.c index f7bf4d6..bdeca6f 100644 --- a/xmem.c +++ b/xmem.c @@ -7,8 +7,10 @@ * $XConsortium: xload.c,v 1.36 91/05/24 16:57:46 converse Exp $ */ -#include #include +#include +#include +#include #include #include #include @@ -157,8 +159,10 @@ int main(int argc, char **argv) /* For security reasons, we reset our uid/gid after doing the necessary system initialization and before calling any X routines. */ - setgid(getgid()); /* reset gid first while still (maybe) root */ - setuid(getuid()); + if (setgid(getgid()) == -1) + errx(1, "%s: setgid failed: %s\n", argv[0], strerror(errno)); + if (setuid(getuid()) == -1) + errx(1, "%s: setuid failed: %s\n", argv[0], strerror(errno)); toplevel = XtAppInitialize(&app_con, "XMem", options_mem, XtNumber(options_mem), &argc, argv, NULL, NULL, (Cardinal) 0); @@ -218,7 +222,10 @@ int main(int argc, char **argv) False); (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), &wm_delete_window, 1); - + + if (pledge("ps vminfo stdio", NULL) == -1) + errx(1, "pledge failed: %s", strerror(errno)); + XtAppMainLoop(app_con); }