dogguts / System.DirectoryServices.Protocol_linux

Proof-Of-Concept Port of dotnet/corefx "System.DirectoryServices.Protocols" to Linux (using libldap)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BerConverter errorhandling (wldap32/winber vs openldap/lber)

dogguts opened this issue · comments

openldap/lber

concerning native ber_* function calls and return values;
Decoding; http://man7.org/linux/man-pages/man3/lber-decode.3.html#ERRORS
Encoding: http://man7.org/linux/man-pages/man3/lber-encode.3.html#ERRORS

In general, these
routines return the length of the element encoded, or -1 if an error
occurred.

eg. ber_scanf ( https://tools.ietf.org/html/draft-ietf-ldapext-ldap-c-api-05#section-17.5

ber_scanf() returns LBER_ERROR on error, and a different value on suc-
cess.

wldap32/winber

eg. ber_scanf

On error, the function returns LBER_ERROR.

BerConverter implementation

Yet despite the above, BerConverter has numerous statements that check whether the return value of ber_* functions compares to 0.
This seems to be true for the wldap32 api.
But the openLdap/lber some functions return values >=0 to indicate success, eg. ber_scanf returns the Tag on success, which with the current BerConverter will be interpreted as an error value.
error

Solution

ber_* function return values should be checked against LBER_ERROR, where

 (returnValue ==LBER_ERROR)   // implies an error
 (returnValue !=LBER_ERROR)   // implies success