Ticket 49441 - Import crashes with large indexed binary
attributes
Bug Description: Importing an ldif file that contains entries with large
binary attributes that are indexed crashes the server.
The crash occurs when "encoding" the binary value to a
string for debug logging, where we "underflow" the buffer
space index which then allows the string buffer to overflow.
Fix Description: While filling the string buffer with the encoded binary
value we need to make sure if the buffer space is greater
than zero before decrementing it.
Also check if trace logging is being used before we actually
call the logging function which calls the "encoded" function
first. This way we avoid this costly "encoding" on every
index call we make.
https://pagure.io/389-ds-base/issue/49441
Reviewed by: firstyear(Thanks!)