~mcepl/ldapvi

92b97c2b9e9d37c869ab94fb55200cc870cccdac — ktetzlaff 7 months ago 0a7705d devel
Fix 'ldapvi --in' issue with base64 encoded dn when (len_dn % 3) == 0

Fix 'ldapvi --in' bug in ldapvi/base64.c read_base64(..) that cause a missing
'\0' terminator when decoding base64 encoded DNs which don't end with
padding (i.e. when (len_decoded_dn % 3) == 0).

Recipe to reproduce the issue without the fix:

Example LDIF file (test.ldif):
--
# dn of 'ou=abc,dc=example,dc=com' (length 24) gets base64 encoded
# without padding
dn:: b3U9YWJjLGRjPWV4YW1wbGUsZGM9Y29t
objectclass: organizationalUnit
ou: abc
--

Running:

    VISUAL=cat ldapvi --in --add test.ldif 2>/dev/null

results in the following output (note the 'sZGM9Y29t' suffix after 'add
ou=abc,dc=example,dc=com'):
--
# -*- coding: utf-8 -*- vim:fileencoding=utf-8:
# http://www.lichteblau.com/ldapvi/manual#syntax

add ou=abc,dc=example,dc=comsZGM9Y29t
objectclass: organizationalUnit
ou: abc
--
1 files changed, 2 insertions(+), 0 deletions(-)

M ldapvi/base64.c
M ldapvi/base64.c => ldapvi/base64.c +2 -0
@@ 278,6 278,8 @@ read_base64(
		 */
		if (state != 0)
			return (-1);
		/* Make sure that target is terminated with nul byte. */
		target[tarindex] = '\0';
	}

	return (tarindex);