Skip to content

Commit b0ea29a

Browse files
JurgenLBThalhammer
andauthored
AppVeyor Warnings (#403)
* Add size checks before casting to int Added checks to ensure sizes fit into int before casting. * Fix windows build without NOMINMAX --------- Co-authored-by: Dominik Thalhammer <thalhammer.d@googlemail.com> Co-authored-by: Dominik Thalhammer <dominik@thalhammer.it>
1 parent b89a5b1 commit b0ea29a

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

include/jwt-cpp/jwt.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,23 @@ namespace jwt {
722722
if (key.substr(0, 27) == "-----BEGIN CERTIFICATE-----") {
723723
auto epkey = helper::extract_pubkey_from_cert<error_category>(key, password, ec);
724724
if (ec) return {};
725-
const int len = static_cast<int>(epkey.size());
725+
// Ensure the size fits into an int before casting
726+
if (epkey.size() > static_cast<std::size_t>((std::numeric_limits<int>::max)())) {
727+
ec = error_category::load_key_bio_write; // Add an appropriate error here
728+
return {};
729+
}
730+
int len = static_cast<int>(epkey.size());
726731
if (BIO_write(pubkey_bio.get(), epkey.data(), len) != len) {
727732
ec = error_category::load_key_bio_write;
728733
return {};
729734
}
730735
} else {
731-
const int len = static_cast<int>(key.size());
736+
// Ensure the size fits into an int before casting
737+
if (key.size() > static_cast<std::size_t>((std::numeric_limits<int>::max)())) {
738+
ec = error_category::load_key_bio_write; // Add an appropriate error here
739+
return {};
740+
}
741+
int len = static_cast<int>(key.size());
732742
if (BIO_write(pubkey_bio.get(), key.data(), len) != len) {
733743
ec = error_category::load_key_bio_write;
734744
return {};

0 commit comments

Comments
 (0)