Check length as well as start when determining static metadata id

reviewable/pr8842/r1
Craig Tiller 8 years ago
parent 1ad51e021f
commit b2348ba1db
  1. 8
      src/core/lib/transport/static_metadata.c
  2. 5
      tools/codegen/core/gen_static_metadata.py

@ -396,10 +396,14 @@ static const uint8_t g_revmap[] = {
int grpc_static_metadata_index(grpc_slice slice) {
if (GRPC_SLICE_LENGTH(slice) == 0) return 33;
size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes);
if (slice.refcount != &g_refcnt) return -1;
size_t ofs = (size_t)(slice.data.refcounted.bytes - g_raw_bytes);
if (ofs > sizeof(g_revmap)) return -1;
uint8_t id = g_revmap[ofs];
return id == 255 ? -1 : id;
return id == 255 ? -1 : (grpc_static_slice_table[id].data.refcounted.length ==
slice.data.refcounted.length
? id
: -1);
}
uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = {

@ -339,10 +339,11 @@ print >>C
print >>H, 'int grpc_static_metadata_index(grpc_slice slice);'
print >>C, 'int grpc_static_metadata_index(grpc_slice slice) {'
print >>C, ' if (GRPC_SLICE_LENGTH(slice) == 0) return %d;' % zero_length_idx
print >>C, ' size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes);'
print >>C, ' if (slice.refcount != &g_refcnt) return -1;'
print >>C, ' size_t ofs = (size_t)(slice.data.refcounted.bytes - g_raw_bytes);'
print >>C, ' if (ofs > sizeof(g_revmap)) return -1;'
print >>C, ' uint8_t id = g_revmap[ofs];'
print >>C, ' return id == 255 ? -1 : id;'
print >>C, ' return id == 255 ? -1 : (grpc_static_slice_table[id].data.refcounted.length == slice.data.refcounted.length? id : -1);'
print >>C, '}'
print >>C

Loading…
Cancel
Save