From 2ad6067ce491446ab22f59a363d36575a942f5c7 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Fri, 27 Aug 2010 14:35:07 -0700 Subject: [PATCH] do not merge: cherry-picked 44db990d3a4ce0edbdd16fa7ac20693ef601b723 from master branch Change-Id: I03e99bfa70ab86eb8eaa2984b6da26a92bd2718a --- adb/adb.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/adb/adb.c b/adb/adb.c index a34dd719b..ca51bf053 100644 --- a/adb/adb.c +++ b/adb/adb.c @@ -885,7 +885,9 @@ int adb_main(int is_daemon) struct __user_cap_header_struct header; struct __user_cap_data_struct cap; - prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0); + if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) { + exit(1); + } /* add extra groups: ** AID_ADB to access the USB driver @@ -899,11 +901,17 @@ int adb_main(int is_daemon) */ gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS, AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_RW, AID_MOUNT }; - setgroups(sizeof(groups)/sizeof(groups[0]), groups); + if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) { + exit(1); + } /* then switch user and group to "shell" */ - setgid(AID_SHELL); - setuid(AID_SHELL); + if (setgid(AID_SHELL) != 0) { + exit(1); + } + if (setuid(AID_SHELL) != 0) { + exit(1); + } /* set CAP_SYS_BOOT capability, so "adb reboot" will succeed */ header.version = _LINUX_CAPABILITY_VERSION;