Loading libkeyutils/mini_keyctl.cpp +11 −6 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "mini_keyctl_utils.h" #include <error.h> #include <stdio.h> #include <unistd.h> Loading @@ -36,6 +37,14 @@ static void Usage(int exit_code) { _exit(exit_code); } static key_serial_t parseKeyOrDie(const char* str) { key_serial_t key; if (!android::base::ParseInt(str, &key)) { error(1 /* exit code */, 0 /* errno */, "Unparsable key: '%s'\n", str); } return key; } int main(int argc, const char** argv) { if (argc < 2) Usage(1); const std::string action = argv[1]; Loading Loading @@ -67,17 +76,13 @@ int main(int argc, const char** argv) { return RestrictKeyring(keyring); } else if (action == "unlink") { if (argc != 4) Usage(1); key_serial_t key = std::stoi(argv[2], nullptr, 16); key_serial_t key = parseKeyOrDie(argv[2]); const std::string keyring = argv[3]; return Unlink(key, keyring); } else if (action == "security") { if (argc != 3) Usage(1); const char* key_str = argv[2]; key_serial_t key; if (!android::base::ParseInt(key_str, &key)) { fprintf(stderr, "Unparsable key: '%s'\n", key_str); return 1; } key_serial_t key = parseKeyOrDie(key_str); std::string context = RetrieveSecurityContext(key); if (context.empty()) { perror(key_str); Loading libkeyutils/mini_keyctl_utils.cpp +2 −5 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/strings.h> #include <keyutils.h> Loading @@ -53,12 +54,8 @@ static bool GetKeyringId(const std::string& keyring_desc, key_serial_t* keyring_ } // If the keyring id is already a hex number, directly convert it to keyring id try { key_serial_t id = std::stoi(keyring_desc, nullptr, 16); *keyring_id = id; if (android::base::ParseInt(keyring_desc.c_str(), keyring_id)) { return true; } catch (const std::exception& e) { LOG(INFO) << "search /proc/keys for keyring id"; } // Only keys allowed by SELinux rules will be shown here. Loading Loading
libkeyutils/mini_keyctl.cpp +11 −6 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "mini_keyctl_utils.h" #include <error.h> #include <stdio.h> #include <unistd.h> Loading @@ -36,6 +37,14 @@ static void Usage(int exit_code) { _exit(exit_code); } static key_serial_t parseKeyOrDie(const char* str) { key_serial_t key; if (!android::base::ParseInt(str, &key)) { error(1 /* exit code */, 0 /* errno */, "Unparsable key: '%s'\n", str); } return key; } int main(int argc, const char** argv) { if (argc < 2) Usage(1); const std::string action = argv[1]; Loading Loading @@ -67,17 +76,13 @@ int main(int argc, const char** argv) { return RestrictKeyring(keyring); } else if (action == "unlink") { if (argc != 4) Usage(1); key_serial_t key = std::stoi(argv[2], nullptr, 16); key_serial_t key = parseKeyOrDie(argv[2]); const std::string keyring = argv[3]; return Unlink(key, keyring); } else if (action == "security") { if (argc != 3) Usage(1); const char* key_str = argv[2]; key_serial_t key; if (!android::base::ParseInt(key_str, &key)) { fprintf(stderr, "Unparsable key: '%s'\n", key_str); return 1; } key_serial_t key = parseKeyOrDie(key_str); std::string context = RetrieveSecurityContext(key); if (context.empty()) { perror(key_str); Loading
libkeyutils/mini_keyctl_utils.cpp +2 −5 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/strings.h> #include <keyutils.h> Loading @@ -53,12 +54,8 @@ static bool GetKeyringId(const std::string& keyring_desc, key_serial_t* keyring_ } // If the keyring id is already a hex number, directly convert it to keyring id try { key_serial_t id = std::stoi(keyring_desc, nullptr, 16); *keyring_id = id; if (android::base::ParseInt(keyring_desc.c_str(), keyring_id)) { return true; } catch (const std::exception& e) { LOG(INFO) << "search /proc/keys for keyring id"; } // Only keys allowed by SELinux rules will be shown here. Loading