From f66f651374485c3fded6aa372c869f870c9793c2 Mon Sep 17 00:00:00 2001 From: James Price Date: Mon, 13 Sep 2021 14:58:39 +0000 Subject: [PATCH] transform/BindingRemapper: Validate access mode Ensure that remapped access modes are valid enum values. NB: This is hard to test, as UBSan flags an out-of-range enum value as a hard error. Fixed: chromium:1248754, chromium:1248755 Change-Id: I2e686843134e6a285fb8316a1960fc4eadff2a93 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/64120 Auto-Submit: James Price Kokoro: Kokoro Commit-Queue: Ben Clayton Reviewed-by: Ben Clayton --- src/ast/access.h | 6 ++++-- src/transform/binding_remapper.cc | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ast/access.h b/src/ast/access.h index 664e5e3ccb..34d93e8535 100644 --- a/src/ast/access.h +++ b/src/ast/access.h @@ -24,13 +24,15 @@ namespace ast { /// The access control settings enum Access { /// Not declared in the source - kUndefined, + kUndefined = 0, /// Read only kRead, /// Write only kWrite, /// Read write - kReadWrite + kReadWrite, + // Last valid access mode + kLastValid = kReadWrite, }; /// @param out the std::ostream to write to diff --git a/src/transform/binding_remapper.cc b/src/transform/binding_remapper.cc index 67d47cd030..adecc8464c 100644 --- a/src/transform/binding_remapper.cc +++ b/src/transform/binding_remapper.cc @@ -113,6 +113,13 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) { auto ac_it = remappings->access_controls.find(from); if (ac_it != remappings->access_controls.end()) { ast::Access ac = ac_it->second; + if (ac > ast::Access::kLastValid) { + ctx.dst->Diagnostics().add_error( + diag::System::Transform, + "invalid access mode (" + + std::to_string(static_cast(ac)) + ")"); + return; + } auto* sem = ctx.src->Sem().Get(var); if (sem->StorageClass() != ast::StorageClass::kStorage) { ctx.dst->Diagnostics().add_error(