arun11299 / cpp-jwt

JSON Web Token library for C++
MIT License
387 stars 112 forks source link

Fix out-of-bounds access in three_parts and mishandling of non-null terminated string_views in jwt_set::case_compare #92

Closed Tradias closed 2 years ago

Tradias commented 2 years ago

Fix out-of-bounds access in three_parts, added an assertion to jwt::string_view to prevent future such errors. Also set CI pipeline build type to Debug.
Fix mishandling of non-null terminated string_views in jwt_set::case_compare, also add noexcept.
Address several conversion and unreachability warnings.

This also fixes a compiler error when using MSVC 17.2 and /std:c++latest

[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xmemory(52): error C3066: there are multiple ways that an object of this type can be called with these arguments
[build] C:\3YOURMIND\cpp-jwt\include\jwt/jwt.hpp(148): note: could be 'bool jwt::jwt_set::case_compare::operator ()(const std::string &,const std::string &) const'
[build] C:\3YOURMIND\cpp-jwt\include\jwt/jwt.hpp(160): note: or       'bool jwt::jwt_set::case_compare::operator ()(const std::string &,const jwt::string_view) const'
[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xmemory(51): note: while trying to match the argument list '(const std::string, const char *const )'
[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xtree(1683): note: see reference to variable template 'const bool _Nothrow_compare<jwt::jwt_set::case_compare,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,char const *>' being compiled
[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xtree(1682): note: while compiling class template member function 'std::pair<std::_Tree_node<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::_Default_allocator_traits<_Alloc>::void_pointer> *,std::_Tree_node<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::_Default_allocator_traits<_Alloc>::void_pointer> *> std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::_Eqrange<_Kx>(const _Other &) noexcept(<expr>) const'
[build]         with
[build]         [
[build]             _Alloc=std::allocator<std::string>,
[build]             _Kty=std::string,
[build]             _Pr=jwt::jwt_set::case_compare,
[build]             _Kx=const char *,
[build]             _Other=const char *
[build]         ]
[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xtree(1338): note: while compiling class template member function 'unsigned __int64 std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::erase<const char*,jwt::jwt_set::case_compare,std::true_type,0>(_Kx &&) noexcept(<expr>)'
[build]         with
[build]         [
[build]             _Kty=std::string,
[build]             _Pr=jwt::jwt_set::case_compare,
[build]             _Alloc=std::allocator<std::string>,
[build]             _Kx=const char *
[build]         ]
[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xmemory(52): error C3066: there are multiple ways that an object of this type can be called with these arguments
[build] C:\3YOURMIND\cpp-jwt\include\jwt/jwt.hpp(148): note: could be 'bool jwt::jwt_set::case_compare::operator ()(const std::string &,const std::string &) const'
[build] C:\3YOURMIND\cpp-jwt\include\jwt/jwt.hpp(160): note: or       'bool jwt::jwt_set::case_compare::operator ()(const std::string &,const jwt::string_view) const'
[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xmemory(52): note: while trying to match the argument list '(const std::string, const char *const )'
[build] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xmemory(51): error C2056: illegal expression
arun11299 commented 2 years ago

I am still little bit skeptical about the return statement removal, mainly from the point of view of other compilers. But it is probably not a big deal. Thanks for the fix.