File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff 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 {};
You can’t perform that action at this time.
0 commit comments