[Date Prev][Date Next] [Chronological] [Thread] [Top]

Tag handling in draft-ietf-ldapext-ldap-c-api-01.txt



A few problems and suggestions for tag handling:

===

Bugfix:

The draft must specify how ber_peek_tag (and thus ber_skip_tag,
ber_first_element and ber_next_element) handle multi-octet tags.
I suggest:

1. Either
     * treat the raw tag octets as little-endian integers, and fail
       if the value is >= LONG_MAX,
     * remove the restriction that tag < 32 in ber_printf("t",tag),
   or
     * fail if the tag value is > 30.
   Both methods let us use (tag & 0xE0) to get the class/encoding bits,
   ensure that tags are != LBER_DEFAULT, and are simple to implement.

   (U-M LDAP accepts multi-octet tags, but the code is buggy.  It sends
   them in network byte order and reads them in host byte order.)

2. Return LBER_DEFAULT if the tag is too large.
   (Don't call it LBER_ERROR; that might give the impression that this
   can be distinguised from LBER_DEFAULT due to EOF.)

===

Improvement:

Sequence elements with unrecognized tags MUST be ignored, but
ber_scanf() does not support this.  I suggest:

ber_scanf:

    Each format character in a ber_scanf format string may be preceded by
    a 't' or 'T' modifier.  They take an int [or unsigned long?]
    argument with a tag.

    `t':
        Skips elements with tags != <tag>. 

    `T':
        Fail with LBER_ERROR if an element to be input has tag != <tag>.

    [To simplify implementation, maybe 't' and 'T' may not be the last
    character in a ber_scanf format string?]

Programs using ber_<first/next>_element would benefit from something
similar, e.g.:

ber_skip_to_tags (BerElement *ber, unsigned long **tags)
        Skips elements until an element with one of the tags in <tags>.
        <tags> = array of tags, ended by LBER_DEFAULT.
        <tags> would contain the tags of the expected optional/default
               elements, plus that of the next mandatory element.

-- 
Hallvard