Skip to content

Commit

Permalink
Prevent failing discriminant checks
Browse files Browse the repository at this point in the history
Ref. #320
  • Loading branch information
treiher committed Jul 8, 2020
1 parent b97170b commit fd14098
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions generated/rflx-ethernet-generic_frame.adb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ is
function Message_Last (Ctx : Context) return Types.Bit_Index is
((if
Structural_Valid (Ctx.Cursors (F_Payload))
and ((Ctx.Cursors (F_Payload).Last - Ctx.Cursors (F_Payload).First + 1)) / 8 >= 46
and ((Ctx.Cursors (F_Payload).Last - Ctx.Cursors (F_Payload).First + 1)) / 8 <= 1500
and then (((Ctx.Cursors (F_Payload).Last - Ctx.Cursors (F_Payload).First + 1)) / 8 >= 46
and ((Ctx.Cursors (F_Payload).Last - Ctx.Cursors (F_Payload).First + 1)) / 8 <= 1500)
then
Ctx.Cursors (F_Payload).Last
else
Expand Down Expand Up @@ -194,7 +194,7 @@ is
when F_TPID =>
(if
Ctx.Cursors (Fld).Predecessor = F_Type_Length_TPID
and Ctx.Cursors (F_Type_Length_TPID).Value.Type_Length_TPID_Value = 16#8100#
and then Ctx.Cursors (F_Type_Length_TPID).Value.Type_Length_TPID_Value = 16#8100#
then
Ctx.Cursors (F_Type_Length_TPID).First
else
Expand All @@ -209,7 +209,7 @@ is
when F_Type_Length =>
(if
Ctx.Cursors (Fld).Predecessor = F_Type_Length_TPID
and Ctx.Cursors (F_Type_Length_TPID).Value.Type_Length_TPID_Value /= 16#8100#
and then Ctx.Cursors (F_Type_Length_TPID).Value.Type_Length_TPID_Value /= 16#8100#
then
Ctx.Cursors (F_Type_Length_TPID).First
elsif
Expand All @@ -221,12 +221,12 @@ is
when F_Payload =>
(if
Ctx.Cursors (Fld).Predecessor = F_Type_Length
and Ctx.Cursors (F_Type_Length).Value.Type_Length_Value <= 1500
and then Ctx.Cursors (F_Type_Length).Value.Type_Length_Value <= 1500
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
elsif
Ctx.Cursors (Fld).Predecessor = F_Type_Length
and Ctx.Cursors (F_Type_Length).Value.Type_Length_Value >= 1536
and then Ctx.Cursors (F_Type_Length).Value.Type_Length_Value >= 1536
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
else
Expand Down
2 changes: 1 addition & 1 deletion generated/rflx-expression-generic_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ is
function Message_Last (Ctx : Context) return Types.Bit_Index is
((if
Structural_Valid (Ctx.Cursors (F_Payload))
and Equal (Ctx, F_Payload, (Types.Byte'Val (1), Types.Byte'Val (2)))
and then Equal (Ctx, F_Payload, (Types.Byte'Val (1), Types.Byte'Val (2)))
then
Ctx.Cursors (F_Payload).Last
else
Expand Down
30 changes: 15 additions & 15 deletions generated/rflx-ipv4-generic_option.adb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ is
function Message_Last (Ctx : Context) return Types.Bit_Index is
((if
Structural_Valid (Ctx.Cursors (F_Option_Number))
and Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 1
and then (Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 1)
then
Ctx.Cursors (F_Option_Number).Last
elsif
Expand Down Expand Up @@ -177,26 +177,26 @@ is
when F_Option_Length =>
(if
Ctx.Cursors (Fld).Predecessor = F_Option_Number
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value > 1
and then Ctx.Cursors (F_Option_Number).Value.Option_Number_Value > 1
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
else
Types.Unreachable_Bit_Length),
when F_Option_Data =>
(if
Ctx.Cursors (Fld).Predecessor = F_Option_Length
and ((Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Debugging_And_Measurement))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 4)
or (Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and (Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 9
or Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 3
or Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 7))
or (Ctx.Cursors (F_Option_Length).Value.Option_Length_Value = 11
and Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 2)
or (Ctx.Cursors (F_Option_Length).Value.Option_Length_Value = 4
and Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 8))
and then ((Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Debugging_And_Measurement))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 4)
or (Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and (Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 9
or Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 3
or Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 7))
or (Ctx.Cursors (F_Option_Length).Value.Option_Length_Value = 11
and Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 2)
or (Ctx.Cursors (F_Option_Length).Value.Option_Length_Value = 4
and Types.U64 (Ctx.Cursors (F_Option_Class).Value.Option_Class_Value) = Types.U64 (To_Base (Control))
and Ctx.Cursors (F_Option_Number).Value.Option_Number_Value = 8))
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
else
Expand Down
8 changes: 4 additions & 4 deletions generated/rflx-ipv4-generic_packet.adb
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ is
when F_Identification =>
(if
Ctx.Cursors (Fld).Predecessor = F_Total_Length
and Types.U64 (Ctx.Cursors (F_Total_Length).Value.Total_Length_Value) >= Types.U64 (Ctx.Cursors (F_IHL).Value.IHL_Value) * 4
and then Types.U64 (Ctx.Cursors (F_Total_Length).Value.Total_Length_Value) >= Types.U64 (Ctx.Cursors (F_IHL).Value.IHL_Value) * 4
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
else
Expand All @@ -343,7 +343,7 @@ is
when F_Flag_DF =>
(if
Ctx.Cursors (Fld).Predecessor = F_Flag_R
and Types.U64 (Ctx.Cursors (F_Flag_R).Value.Flag_R_Value) = Types.U64 (To_Base (False))
and then Types.U64 (Ctx.Cursors (F_Flag_R).Value.Flag_R_Value) = Types.U64 (To_Base (False))
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
else
Expand Down Expand Up @@ -400,15 +400,15 @@ is
when F_Options =>
(if
Ctx.Cursors (Fld).Predecessor = F_Destination
and Ctx.Cursors (F_IHL).Value.IHL_Value > 5
and then Ctx.Cursors (F_IHL).Value.IHL_Value > 5
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
else
Types.Unreachable_Bit_Length),
when F_Payload =>
(if
Ctx.Cursors (Fld).Predecessor = F_Destination
and Ctx.Cursors (F_IHL).Value.IHL_Value = 5
and then Ctx.Cursors (F_IHL).Value.IHL_Value = 5
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
elsif
Expand Down
4 changes: 2 additions & 2 deletions generated/rflx-tlv-generic_message.adb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ is
function Message_Last (Ctx : Context) return Types.Bit_Index is
((if
Structural_Valid (Ctx.Cursors (F_Tag))
and Types.U64 (Ctx.Cursors (F_Tag).Value.Tag_Value) = Types.U64 (To_Base (Msg_Error))
and then Types.U64 (Ctx.Cursors (F_Tag).Value.Tag_Value) = Types.U64 (To_Base (Msg_Error))
then
Ctx.Cursors (F_Tag).Last
elsif
Expand Down Expand Up @@ -111,7 +111,7 @@ is
when F_Length =>
(if
Ctx.Cursors (Fld).Predecessor = F_Tag
and Types.U64 (Ctx.Cursors (F_Tag).Value.Tag_Value) = Types.U64 (To_Base (Msg_Data))
and then Types.U64 (Ctx.Cursors (F_Tag).Value.Tag_Value) = Types.U64 (To_Base (Msg_Data))
then
(Ctx.Cursors (Ctx.Cursors (Fld).Predecessor).Last + 1)
else
Expand Down
4 changes: 2 additions & 2 deletions rflx/generator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ def first(field: Field, message: Message) -> Expr:
If(
[
(
And(
AndThen(
Equal(
Selected(
Indexed(Variable("Ctx.Cursors"), Variable("Fld")),
Expand Down Expand Up @@ -1452,7 +1452,7 @@ def __create_message_last_function(message: Message) -> UnitPart:
If(
[
(
And(
AndThen(
Call(
"Structural_Valid",
[
Expand Down

0 comments on commit fd14098

Please sign in to comment.