OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" | 5 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 }; | 111 }; |
112 | 112 |
113 class IfThenResultExprImpl : public internal::ResultExprImpl { | 113 class IfThenResultExprImpl : public internal::ResultExprImpl { |
114 public: | 114 public: |
115 IfThenResultExprImpl(const BoolExpr& cond, | 115 IfThenResultExprImpl(const BoolExpr& cond, |
116 const ResultExpr& then_result, | 116 const ResultExpr& then_result, |
117 const ResultExpr& else_result) | 117 const ResultExpr& else_result) |
118 : cond_(cond), then_result_(then_result), else_result_(else_result) {} | 118 : cond_(cond), then_result_(then_result), else_result_(else_result) {} |
119 | 119 |
120 CodeGen::Node Compile(PolicyCompiler* pc) const override { | 120 CodeGen::Node Compile(PolicyCompiler* pc) const override { |
121 return cond_->Compile( | 121 // We compile the "then" and "else" expressions in separate statements so |
122 pc, then_result_->Compile(pc), else_result_->Compile(pc)); | 122 // they have a defined sequencing. See https://crbug.com/529480. |
| 123 CodeGen::Node then_node = then_result_->Compile(pc); |
| 124 CodeGen::Node else_node = else_result_->Compile(pc); |
| 125 return cond_->Compile(pc, then_node, else_node); |
123 } | 126 } |
124 | 127 |
125 bool HasUnsafeTraps() const override { | 128 bool HasUnsafeTraps() const override { |
126 return then_result_->HasUnsafeTraps() || else_result_->HasUnsafeTraps(); | 129 return then_result_->HasUnsafeTraps() || else_result_->HasUnsafeTraps(); |
127 } | 130 } |
128 | 131 |
129 private: | 132 private: |
130 ~IfThenResultExprImpl() override {} | 133 ~IfThenResultExprImpl() override {} |
131 | 134 |
132 BoolExpr cond_; | 135 BoolExpr cond_; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 new const IfThenResultExprImpl(clause.first, clause.second, expr)); | 368 new const IfThenResultExprImpl(clause.first, clause.second, expr)); |
366 } | 369 } |
367 return expr; | 370 return expr; |
368 } | 371 } |
369 | 372 |
370 } // namespace bpf_dsl | 373 } // namespace bpf_dsl |
371 } // namespace sandbox | 374 } // namespace sandbox |
372 | 375 |
373 template class scoped_refptr<const sandbox::bpf_dsl::internal::BoolExprImpl>; | 376 template class scoped_refptr<const sandbox::bpf_dsl::internal::BoolExprImpl>; |
374 template class scoped_refptr<const sandbox::bpf_dsl::internal::ResultExprImpl>; | 377 template class scoped_refptr<const sandbox::bpf_dsl::internal::ResultExprImpl>; |
OLD | NEW |