diff options
-rw-r--r-- | src/android.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/android.c b/src/android.c index 7406ffa..b748ca5 100644 --- a/src/android.c +++ b/src/android.c @@ -563,6 +563,7 @@ static int seapp_context_lookup(enum seapp_kind kind, const char *path, context_t ctx) { + struct passwd *pwd; bool isOwner; const char *username = NULL; struct seapp_context *cur = NULL; @@ -586,14 +587,19 @@ static int seapp_context_lookup(enum seapp_kind kind, isOwner = (userid == 0); appid = uid % AID_USER; if (appid < AID_APP) { - for (n = 0; n < android_id_count; n++) { - if (android_ids[n].aid == appid) { - username = android_ids[n].name; - break; - } - } - if (!username) + /* + * This code is Android specific, bionic guarantees that + * calls to non-reentrant getpwuid() are thread safe. + */ +#ifndef __BIONIC__ +#warning "This code assumes that getpwuid is thread safe, only true with Bionic!" +#endif + pwd = getpwuid(appid); + if (!pwd) goto err; + + username = pwd->pw_name; + } else if (appid < AID_ISOLATED_START) { username = "_app"; appid -= AID_APP; |