mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
binpac: Fix array bounds checking
For arrays that are fields within a record, the bounds check was based on a pointer to the start of the record rather than the start of the array field.
This commit is contained in:
parent
de87adf398
commit
46e2490cb0
1 changed files with 6 additions and 4 deletions
|
@ -320,16 +320,18 @@ void ArrayType::GenArrayLength(Output *out_cc, Env *env, const DataPtr& data)
|
|||
env->RValue(arraylength_var()));
|
||||
}
|
||||
|
||||
out_cc->println("if ( t_begin_of_data + %s > t_end_of_data || "
|
||||
"t_begin_of_data + %s < t_begin_of_data )",
|
||||
array_size.c_str(), array_size.c_str());
|
||||
const char* array_ptr_expr = data.ptr_expr();
|
||||
|
||||
out_cc->println("if ( %s + %s > %s || %s + %s < %s )",
|
||||
array_ptr_expr, array_size.c_str(), env->RValue(end_of_data),
|
||||
array_ptr_expr, array_size.c_str(), array_ptr_expr);
|
||||
out_cc->inc_indent();
|
||||
out_cc->println("throw binpac::ExceptionOutOfBound(\"%s\",",
|
||||
data_id_str_.c_str());
|
||||
out_cc->println(" %s, (%s) - (%s));",
|
||||
array_size.c_str(),
|
||||
env->RValue(end_of_data),
|
||||
env->RValue(begin_of_data));
|
||||
array_ptr_expr);
|
||||
out_cc->dec_indent();
|
||||
}
|
||||
else if ( attr_restofdata_ )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue