Skip to content

Commit

Permalink
transport: verify that strings are valid utf8
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
  • Loading branch information
pdziepak committed Jul 9, 2015
1 parent ac776d2 commit 4273c6d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions transport/server.cc
Expand Up @@ -8,6 +8,7 @@
#include <boost/range/irange.hpp>
#include <boost/bimap.hpp>
#include <boost/assign.hpp>
#include <boost/locale/encoding_utf.hpp>

#include "db/consistency_level.hh"
#include "core/future-util.hh"
Expand Down Expand Up @@ -175,6 +176,14 @@ class cql_server::connection {
}
}

void validate_utf8(sstring_view s) {
try {
boost::locale::conv::utf_to_utf<char>(s.data(), boost::locale::conv::stop);
} catch (const boost::locale::conv::conversion_error& ex) {
throw transport::protocol_exception("Cannot decode string as UTF8");
}
}

int8_t read_byte(temporary_buffer<char>& buf);
int32_t read_int(temporary_buffer<char>& buf);
int64_t read_long(temporary_buffer<char>& buf);
Expand Down Expand Up @@ -677,6 +686,7 @@ sstring cql_server::connection::read_string(temporary_buffer<char>& buf)
sstring s{buf.begin(), static_cast<size_t>(n)};
assert(n >= 0);
buf.trim_front(n);
validate_utf8(s);
return s;
}

Expand All @@ -686,6 +696,7 @@ sstring_view cql_server::connection::read_long_string_view(temporary_buffer<char
check_room(buf, n);
sstring_view s{buf.begin(), static_cast<size_t>(n)};
buf.trim_front(n);
validate_utf8(s);
return s;
}

Expand Down

0 comments on commit 4273c6d

Please sign in to comment.