Merge pull request #508 from haberman/ubsan

Enabled ubsan tests and fixed ubsan failures.
pull/13171/head
Joshua Haberman 3 years ago committed by GitHub
commit a02d92e025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .github/workflows/bazel_tests.yml
  2. 2
      upb/decode.c
  3. 14
      upb/encode.c
  4. 4
      upb/util/def_to_proto.c
  5. 6
      upb/util/required_fields.c

@ -22,7 +22,8 @@ jobs:
- { CC: clang, os: ubuntu-20.04, flags: "-c opt" } # Some warnings only fire with -c opt
- { CC: gcc, os: ubuntu-20.04, flags: "-c opt" }
- { CC: clang, os: ubuntu-20.04, flags: "--//:fasttable_enabled=true -- -cmake:test_generated_files" }
- { CC: clang, os: ubuntu-20.04, flags: "--config=asan -- -benchmarks:benchmark -python/..." }
- { CC: clang, os: ubuntu-20.04, flags: "--config=asan -c dbg -- -benchmarks:benchmark -python/..." }
- { CC: clang, os: ubuntu-20.04, flags: "--config=ubsan -c dbg -- -benchmarks:benchmark -python/... -upb/bindings/lua/...", install: "libunwind-dev" }
- { CC: clang, os: macos-11, flags: "" }
steps:

@ -1066,7 +1066,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg,
if (size <= 16) {
memset(&state.patch, 0, 32);
memcpy(&state.patch, buf, size);
if (size) memcpy(&state.patch, buf, size);
buf = state.patch;
state.end = buf + size;
state.limit = 0;

@ -550,12 +550,14 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
}
}
const upb_MiniTable_Field* f = &m->fields[m->field_count];
const upb_MiniTable_Field* first = &m->fields[0];
while (f != first) {
f--;
if (encode_shouldencode(e, msg, m->subs, f)) {
encode_field(e, msg, m->subs, f);
if (m->field_count) {
const upb_MiniTable_Field* f = &m->fields[m->field_count];
const upb_MiniTable_Field* first = &m->fields[0];
while (f != first) {
f--;
if (encode_shouldencode(e, msg, m->subs, f)) {
encode_field(e, msg, m->subs, f);
}
}
}

@ -453,14 +453,14 @@ static google_protobuf_FileDescriptorProto* filedef_toproto(
google_protobuf_FileDescriptorProto_resize_public_dependency(proto, n,
ctx->arena);
const int32_t* public_dep_nums = _upb_FileDef_PublicDependencyIndexes(f);
memcpy(public_deps, public_dep_nums, n * sizeof(int32_t));
if (n) memcpy(public_deps, public_dep_nums, n * sizeof(int32_t));
n = upb_FileDef_WeakDependencyCount(f);
int32_t* weak_deps =
google_protobuf_FileDescriptorProto_resize_weak_dependency(proto, n,
ctx->arena);
const int32_t* weak_dep_nums = _upb_FileDef_WeakDependencyIndexes(f);
memcpy(weak_deps, weak_dep_nums, n * sizeof(int32_t));
if (n) memcpy(weak_deps, weak_dep_nums, n * sizeof(int32_t));
n = upb_FileDef_TopLevelMessageCount(f);
google_protobuf_DescriptorProto** msgs =

@ -216,8 +216,10 @@ static void upb_util_FindUnsetInMessage(upb_FindContext* ctx,
// Append the contents of the stack to the out array, then
// NULL-terminate.
upb_FieldPathVector_Reserve(ctx, &ctx->out_fields, ctx->stack.size + 2);
memcpy(&ctx->out_fields.path[ctx->out_fields.size], ctx->stack.path,
ctx->stack.size * sizeof(*ctx->stack.path));
if (ctx->stack.size) {
memcpy(&ctx->out_fields.path[ctx->out_fields.size], ctx->stack.path,
ctx->stack.size * sizeof(*ctx->stack.path));
}
ctx->out_fields.size += ctx->stack.size;
ctx->out_fields.path[ctx->out_fields.size++] =
(upb_FieldPathEntry){.field = f};

Loading…
Cancel
Save