Merge pull request #20109 from veblush/smetadata

Fix buffer-overflow in grpc_static_mdelem_for_static_strings
pull/20160/head
Esun Kim 5 years ago committed by GitHub
commit 1168c903c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/core/lib/transport/static_metadata.cc
  2. 14
      test/core/transport/BUILD
  3. 51
      test/core/transport/static_metadata_test.cc
  4. 3
      tools/codegen/core/gen_static_metadata.py

@ -1217,12 +1217,7 @@ static const uint16_t elem_keys[] = {
9076, 9185, 9294, 9403, 9512, 9621, 6242, 9730, 9839, 9948, 10057,
10166, 1189, 538, 10275, 10384, 212, 10493, 1195, 1196, 1197, 1198,
1080, 10602, 1843, 11365, 0, 0, 0, 1734, 0, 1850, 0,
0, 0, 356, 1627, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0};
0, 0, 356, 1627};
static const uint8_t elem_idxs[] = {
7, 8, 9, 10, 11, 12, 13, 76, 78, 71, 1, 2, 5, 6, 25, 3,
4, 66, 65, 30, 83, 62, 63, 67, 61, 73, 57, 37, 14, 19, 21, 22,

@ -82,6 +82,20 @@ grpc_cc_test(
],
)
grpc_cc_test(
name = "static_metadata_test",
srcs = ["static_metadata_test.cc"],
external_deps = [
"gtest",
],
language = "C++",
deps = [
"//:gpr",
"//:grpc",
"//test/core/util:grpc_test_util",
],
)
grpc_cc_test(
name = "status_conversion_test",
srcs = ["status_conversion_test.cc"],

@ -0,0 +1,51 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <gtest/gtest.h>
#include <grpc/grpc.h>
#include "src/core/lib/transport/metadata.h"
#include "src/core/lib/transport/static_metadata.h"
#include "test/core/util/test_config.h"
namespace grpc_core {
namespace {
TEST(StaticMetadataTest, ReadAllStaticElements) {
// This makes sure that all static elements are returned when
// grpc_mdelem_from_slices is called with key pairs pregenerated.
for (int i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) {
const grpc_mdelem mdelem = grpc_static_mdelem_manifested()[i];
const grpc_mdelem mdelem2 =
grpc_mdelem_from_slices(GRPC_MDKEY(mdelem), GRPC_MDVALUE(mdelem));
EXPECT_EQ(mdelem.payload, mdelem2.payload);
}
}
} // namespace
} // namespace grpc_core
int main(int argc, char** argv) {
grpc_init();
grpc::testing::TestEnvironment env(argc, argv);
::testing::InitGoogleTest(&argc, argv);
int retval = RUN_ALL_TESTS();
grpc_shutdown();
return retval;
}

@ -627,7 +627,6 @@ def perfect_hash(keys, name):
return x + p.r[y]
return {
'PHASHRANGE': p.t - 1 + max(p.r),
'PHASHNKEYS': len(p.slots),
'pyfunc': f,
'code': """
@ -659,7 +658,7 @@ elem_keys = [
elem_hash = perfect_hash(elem_keys, 'elems')
print >> C, elem_hash['code']
keys = [0] * int(elem_hash['PHASHRANGE'])
keys = [0] * int(elem_hash['PHASHNKEYS'])
idxs = [255] * int(elem_hash['PHASHNKEYS'])
for i, k in enumerate(elem_keys):
h = elem_hash['pyfunc'](k)

Loading…
Cancel
Save