summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-03-11 10:34:57 +0000
committerPavel Labath <pavel@labath.sk>2019-03-11 10:34:57 +0000
commit7bfa8ea9de45f51d77a2ee5d90f159e012627a9f (patch)
tree93973b02b84449d950c3b34d2e688baec1b34827
parent9318db0fa1992dbfdcad543105b0e38a4df6efc9 (diff)
downloadbcm5719-llvm-7bfa8ea9de45f51d77a2ee5d90f159e012627a9f.tar.gz
bcm5719-llvm-7bfa8ea9de45f51d77a2ee5d90f159e012627a9f.zip
Fix invalid use of StringRef::data in Socket::DecodeHostAndPort
the input StringRef is not guaranteed to be null-terminated, so using data to get the c string is wrong. Luckily, in two of the usages the target function already accepts a StringRef so we can just drop the data() call, and the third one is easily replaced by a stringref-aware function. Issue found by msan. llvm-svn: 355817
-rw-r--r--lldb/source/Host/common/Socket.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp
index 5a3b0c1e5da..7bafee57f5f 100644
--- a/lldb/source/Host/common/Socket.cpp
+++ b/lldb/source/Host/common/Socket.cpp
@@ -259,8 +259,8 @@ bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
llvm::StringRef("([^:]+|\\[[0-9a-fA-F:]+.*\\]):([0-9]+)"));
RegularExpression::Match regex_match(2);
if (g_regex.Execute(host_and_port, &regex_match)) {
- if (regex_match.GetMatchAtIndex(host_and_port.data(), 1, host_str) &&
- regex_match.GetMatchAtIndex(host_and_port.data(), 2, port_str)) {
+ if (regex_match.GetMatchAtIndex(host_and_port, 1, host_str) &&
+ regex_match.GetMatchAtIndex(host_and_port, 2, port_str)) {
// IPv6 addresses are wrapped in [] when specified with ports
if (host_str.front() == '[' && host_str.back() == ']')
host_str = host_str.substr(1, host_str.size() - 2);
@@ -283,9 +283,7 @@ bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
// integer, representing a port with an empty host.
host_str.clear();
port_str.clear();
- bool ok = false;
- port = StringConvert::ToUInt32(host_and_port.data(), UINT32_MAX, 10, &ok);
- if (ok && port < UINT16_MAX) {
+ if (to_integer(host_and_port, port, 10) && port < UINT16_MAX) {
port_str = host_and_port;
if (error_ptr)
error_ptr->Clear();
OpenPOWER on IntegriCloud