Check that stores are permitted by the pointer's storage access.

Fixes #1533.
This commit is contained in:
Jim Blandy authored and Dzmitry Malyshau committed 2021-11-16 23:40:56 -05:00
1 parent 3d6cbcf8a6
commit ce18eba695
5 files changed
+73 -5

No files matched your search

+15 -3
View File
@@ -606,10 +606,12 @@ impl super::Validator {
}
_ => {}
}
let good = match *context
let pointer_ty = context
.resolve_pointer_type(pointer)
.map_err(|e| e.with_span())?
{
.map_err(|e| e.with_span())?;
let good = match *pointer_ty {
Ti::Pointer { base, class: _ } => match context.types[base].inner {
Ti::Atomic { kind, width } => *value_ty == Ti::Scalar { kind, width },
ref other => value_ty == other,
@@ -634,6 +636,16 @@ impl super::Validator {
.with_handle(pointer, context.expressions)
.with_handle(value, context.expressions));
}
if let Some(class) = pointer_ty.pointer_class() {
if !class.access().contains(crate::StorageAccess::STORE) {
return Err(FunctionError::InvalidStorePointer(pointer)
.with_span_static(
context.expressions.get_span(pointer),
"writing to this location is not permitted",
));
}
}
}
S::ImageStore {
image,