Skip to content

Commit

Permalink
Fix extracting certificate id
Browse files Browse the repository at this point in the history
std::strtol() expects null-terminated string. This means that passing
string_view.data() to it may cause undefined behaviour.

Let's fix it by using boost::convert instead.

Tested: Manually by sending valid requests and looking for empty
responses.

Change-Id: I319277551b5e85586783afdc8c86e4a7d8db876e
Signed-off-by: Iwona Klimaszewska <iwona.klimaszewska@intel.com>
  • Loading branch information
Iwona Klimaszewska committed Nov 21, 2019
1 parent fd4859a commit e6604b1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions redfish-core/lib/certificate_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "node.hpp"

#include <boost/convert.hpp>
#include <boost/convert/strtol.hpp>
#include <variant>
namespace redfish
{
Expand Down Expand Up @@ -104,17 +106,14 @@ long getIDFromURL(const std::string_view url)
{
return -1;
}

if ((found + 1) < url.length())
{
char *endPtr;
std::string_view str = url.substr(found + 1);
long value = std::strtol(str.data(), &endPtr, 10);
if (endPtr != str.end())
{
return -1;
}
return value;

return boost::convert<long>(str, boost::cnv::strtol()).value_or(-1);
}

return -1;
}

Expand Down

0 comments on commit e6604b1

Please sign in to comment.