[langsec-discuss] Supporting length fields in grammar formalisms

David-Sarah Hopwood david-sarah at jacaranda.org
Thu Jun 14 02:16:36 UTC 2012


On 14/06/12 02:51, David-Sarah Hopwood wrote:
> Example 1 -- TCPv4 options as defined in http://tools.ietf.org/html/rfc793#section-3.1,
> plus the "Packet Mood" option from http://tools.ietf.org/html/rfc5841 [*]:
> 
> For simplicity we take the End-Of-Option option's Kind field as being part of the
> padding.
> 
>   OptionsAndPadding  =  *Option *Padding
>   Option             =  NoOpOption / KnownOption / UnknownOption
>   Padding            =  %x00
>   NoOpOption         =  %x01
>   KnownOption        =  MSSOption / MoodOption
> 
>   MSSOption          =  %x02 @1+2(MaxSegmentSize)
>   MaxSegmentSize     =  2*BYTE
> 
>   MoodOption         =  %x19 @1+2(Emoticon)
>   Emoticon           =  *(%x00-7F)
> 
>   UnknownOption      =  (%x03-18 / %x1A-FF) @1+2(*BYTE)

BTW, this would be equivalent to

    UnknownOption      =  (%x03-18 / %x1A-FF) @1+2(*253BYTE)

because for more than 253 bytes, the length (plus the offset of 2) wouldn't be
representable in a single byte. In general, the limit on the element size is
256^lengthfieldsize - lengthoffset - 1 bytes. Here, it's easy to modify the
grammar to explicitly state that constraint, but in general it wouldn't be
because the element definition could be arbitrarily complicated.

Also, when I say bytes, I really mean elements of the alphabet over which the
grammar is defined. If it's a syntactic rather than a lexical grammar, we could
define another extension for lengths in terms of lexical elements, if that turned
out to be useful.


Incidentally, the errata of RFC 5234 for ABNF (the first three, anyway) make
interesting reading:

http://www.rfc-editor.org/errata_search.php?rfc=5234

and demonstrate the need to mechanically check grammars for ambiguity.

-- 
David-Sarah Hopwood ⚥

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 554 bytes
Desc: OpenPGP digital signature
URL: <https://lists.langsec.org/pipermail/langsec-discuss/attachments/20120614/b5c6e5fa/attachment.pgp>


More information about the langsec-discuss mailing list