diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2019-09-14 07:51:47 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2019-09-14 07:51:47 +0300 |
commit | b34a90793af54c8b7a1e84846bfb73b47c9d8365 (patch) | |
tree | c14d3b651dcf122bdf1deae3443666cc6be4e001 | |
parent | ab888ceb4ad8177e73f22f0e40cf30d57e92761a (diff) |
new_gpg: improoved error handling on public keys array import from
main menu
-rwxr-xr-x | plugins/New_GPG/src/utilities.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index 53a9ec0edc..ecf3610821 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -1398,15 +1398,19 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM) key += line; key += '\n'; if (strstr(line, "-----END PGP PUBLIC KEY BLOCK-----")) { - std::string::size_type p1 = 0, p2 = 0; - p1 = key.find("Comment: login "); + std::string::size_type p1 = key.rfind("Comment: login "), p2 = 0; + if (p1 == std::string::npos) + { + key.clear(); + continue; //TODO: warning about malformed file + } p1 += mir_strlen("Comment: login "); - p2 = key.find(" contact_id "); + p2 = key.rfind(" contact_id "); login = key.substr(p1, p2 - p1); p2 += mir_strlen(" contact_id "); p1 = key.find("\n", p2); contact_id = key.substr(p2, p1 - p2); - p1 = key.find("Comment: login "); + p1 = key.rfind("Comment: login "); p2 = key.find("\n", p1); p2++; key.erase(p1, p2 - p1); @@ -1648,7 +1652,7 @@ INT_PTR ImportGpGKeys(WPARAM, LPARAM) } key.clear(); } - if (strstr(line, "-----END PGP PRIVATE KEY BLOCK-----")) { + else if (strstr(line, "-----END PGP PRIVATE KEY BLOCK-----")) { std::vector<wstring> cmd; wchar_t tmp2[MAX_PATH] = { 0 }; wchar_t *ptmp; |