Sunday, August 28, 2016

[389-devel] Sign compare checking

Hi,

I'm going through the list of sign-compare errors from gcc, and putting
in the appropriate casts (uint -> int normally).

I found in filter.c:

/* openldap does not return LBER_END_OF_SEQORSET -
so check for len == -1 - openldap ber_next_element will not
set
len if it has reached the end, and -1 is not a valid value
for a real len */
if ( (tag != LBER_END_OF_SEQORSET) && (len != -1) && (*fstr !=
NULL) ) {
LDAPDebug( LDAP_DEBUG_ANY, " error parsing filter list
\n", 0, 0, 0 );
slapi_ch_free((void**)fstr );
}


However, len is a ber_len_t, which is a typedef uint. It's actually
impossible for this value to hold a -1.

So either, this is a bug in the way openldap uses the ber_len_t type, we
have a mistake in our logic, or something else hokey is going on.

I would like to update this to:

if ( (tag != LBER_END_OF_SEQORSET) && (len == 0) && (*fstr != NULL) )

Or even:

if ( (tag != LBER_END_OF_SEQORSET) && (*fstr != NULL) )

What do you think of this assessment given the ber_len_t type?

--
Sincerely,

William Brown
Software Engineer
Red Hat, Brisbane

No comments:

Post a Comment