[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openldap-devel
Subject:    Re: ldap_get_values() called on binary data - does this return an error, or garbage data?
From:       Ondřej Kuzník <ondra () mistotebe ! net>
Date:       2024-04-03 12:03:09
Message-ID: Zg1Ffee8UXGHMNDO () mistotebe ! net
[Download RAW message or body]

On Wed, Apr 03, 2024 at 10:55:26AM +0100, Graham Leggett wrote:
> Hi all,
> 
> Looking back in time to the definitions of ldap_get_values() and
> ldap_get_values_len(), we are told that "If the attribute values are
> binary in nature, and thus not suitable to be returned as an array of
> char *'s, the ldap_get_values_len() routine can be used instead."
> 
> This has been historically vague - first off, what happens if an
> attempt is made to call ldap_get_values() on binary data, do you get
> an error, or garbage data? The source isn't giving me a clear answer.

Hi Graham,
in this case binary data means embedded NULs (\0) can be found: given
that what you get back is a naive char * for each value, you stand to
lose information about whether that NUL is part of the value or a
string terminator.

> Second question is how do you know which of ldap_get_values() or
> ldap_get_values_len() to call? Obviously you can manually know this,
> but I'm interested in automated behaviour. What is the canonical way
> to discover that if you queried a jpegPhoto (for example) that the
> result would be binary?

You either expect the data to be a string of some sort (no embedded
NULs), then you're free to use whichever or you are prepared to accept
arbitrary bytestreams and you need to use the one that returns bervals.
That's all there is.

You're welcome to propose better wording if you can make it clearer to a
reasonably competent C developer (I'm sure we can assume that they
understand how strings are laid out etc.)

Regards,

-- 
Ondřej Kuzník
Senior Software Engineer
Symas Corporation                       http://www.symas.com
Packaged, certified, and supported LDAP solutions powered by OpenLDAP
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic