Commit e4c97b8b authored by Bence Béky's avatar Bence Béky Committed by Commit Bot

Use base::RandBytes() to generate greased HTTP/2 frame flag byte.

The primary motivation is that the previous incantation looked
suspicions: even though the rules of C++ are very clear about type
casting when adding 255 as a uint8 and 1 as an int and then using it as
an argument for a function that takes a uint64, it is too much to think
about.  This CL uses RandBytes() instead of read a single byte.

(Incidentally RandGenerator() implementation is a bit complicated, and
always reads 64 random bytes, quite unnecessarily in this case.)

Bug: 1020233
Change-Id: I3e5610779c1643f86f2d615915931903d4962448
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906466
Commit-Queue: Ryan Hamilton <rch@chromium.org>
Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713932}
parent 7586e11d
...@@ -151,12 +151,15 @@ void ConfigureHttp2Params(const base::CommandLine& command_line, ...@@ -151,12 +151,15 @@ void ConfigureHttp2Params(const base::CommandLine& command_line,
GetVariationParam(http2_trial_params, "http2_grease_frame_type") == GetVariationParam(http2_trial_params, "http2_grease_frame_type") ==
"true") { "true") {
const uint8_t type = 0x0b + 0x1f * base::RandGenerator(8); const uint8_t type = 0x0b + 0x1f * base::RandGenerator(8);
const uint8_t flags =
base::RandGenerator(std::numeric_limits<uint8_t>::max() + 1); uint8_t flags;
base::RandBytes(&flags, /* output_length = */ sizeof(flags));
const size_t length = base::RandGenerator(7); const size_t length = base::RandGenerator(7);
// RandBytesAsString() does not support zero length. // RandBytesAsString() does not support zero length.
const std::string payload = const std::string payload =
(length > 0) ? base::RandBytesAsString(length) : std::string(); (length > 0) ? base::RandBytesAsString(length) : std::string();
params->greased_http2_frame = params->greased_http2_frame =
base::Optional<net::SpdySessionPool::GreasedHttp2Frame>( base::Optional<net::SpdySessionPool::GreasedHttp2Frame>(
{type, flags, payload}); {type, flags, payload});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment