diff options
author | Tom Cherry <tomcherry@google.com> | 2017-05-04 17:40:33 -0700 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2017-05-05 14:37:01 -0700 |
commit | 517e1f17cfec2143d4d10a64b1496a550acf3ea2 (patch) | |
tree | eda028c6359878b7f5d3ab56d2dc65a4ac1cad39 /init/init_parser_test.cpp | |
parent | 3d7ee068e0a0ce707965835f58abce65189abda4 (diff) |
init: Check DecodeUid() result and use error string
Check the result of DecodeUid() and return failure when uids/gids are
unable to be decoded.
Also, use an error string instead of logging directly such that more
context can be added when decoding fails.
Bug: 38038887
Test: Boot bullhead
Test: Init unit tests
Change-Id: I84c11aa5a8041bf5d2f754ee9af748344b789b37
Diffstat (limited to 'init/init_parser_test.cpp')
-rw-r--r-- | init/init_parser_test.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/init/init_parser_test.cpp b/init/init_parser_test.cpp index d8fd2bab9..86d60d024 100644 --- a/init/init_parser_test.cpp +++ b/init/init_parser_test.cpp @@ -86,19 +86,29 @@ static void Test_make_exec_oneshot_service(bool dash_dash, bool seclabel, bool u ASSERT_EQ("", svc->seclabel()); } if (uid) { - ASSERT_EQ(decode_uid("log"), svc->uid()); + uid_t decoded_uid; + std::string err; + ASSERT_TRUE(DecodeUid("log", &decoded_uid, &err)); + ASSERT_EQ(decoded_uid, svc->uid()); } else { ASSERT_EQ(0U, svc->uid()); } if (gid) { - ASSERT_EQ(decode_uid("shell"), svc->gid()); + uid_t decoded_uid; + std::string err; + ASSERT_TRUE(DecodeUid("shell", &decoded_uid, &err)); + ASSERT_EQ(decoded_uid, svc->gid()); } else { ASSERT_EQ(0U, svc->gid()); } if (supplementary_gids) { ASSERT_EQ(2U, svc->supp_gids().size()); - ASSERT_EQ(decode_uid("system"), svc->supp_gids()[0]); - ASSERT_EQ(decode_uid("adb"), svc->supp_gids()[1]); + uid_t decoded_uid; + std::string err; + ASSERT_TRUE(DecodeUid("system", &decoded_uid, &err)); + ASSERT_EQ(decoded_uid, svc->supp_gids()[0]); + ASSERT_TRUE(DecodeUid("adb", &decoded_uid, &err)); + ASSERT_EQ(decoded_uid, svc->supp_gids()[1]); } else { ASSERT_EQ(0U, svc->supp_gids().size()); } |