Module: wine Branch: stable Commit: 70e46a9ddaa9212591ca91ee80511c36e6f347af URL: https://gitlab.winehq.org/wine/wine/-/commit/70e46a9ddaa9212591ca91ee80511c3...
Author: Alex Henrie alexhenrie24@gmail.com Date: Tue Mar 21 00:18:20 2023 -0600
wldap32: Handle null DN or null message in ldap_modify* and add tests.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54702 (cherry picked from commit 320c688ed3393c688717404941caf09024baa046)
---
dlls/wldap32/modify.c | 8 +++--- dlls/wldap32/tests/parse.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-)
diff --git a/dlls/wldap32/modify.c b/dlls/wldap32/modify.c index a062bf4bb15..2dea3279151 100644 --- a/dlls/wldap32/modify.c +++ b/dlls/wldap32/modify.c @@ -79,7 +79,7 @@ ULONG CDECL ldap_modify_extA( LDAP *ld, char *dn, LDAPModA **mods, LDAPControlA
TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), mods, serverctrls, clientctrls, message );
- if (!ld) return ~0u; + if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
if (dn && !(dnW = strAtoW( dn ))) goto exit; if (mods && !(modsW = modarrayAtoW( mods ))) goto exit; @@ -109,9 +109,9 @@ ULONG CDECL ldap_modify_extW( LDAP *ld, WCHAR *dn, LDAPModW **mods, LDAPControlW
TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), mods, serverctrls, clientctrls, message );
- if (!ld) return ~0u; + if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
- if (dn && !(dnU = strWtoU( dn ))) goto exit; + if (!(dnU = dn ? strWtoU( dn ) : strdup( "" ))) goto exit; if (mods && !(modsU = modarrayWtoU( mods ))) goto exit; if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit; if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit; @@ -173,7 +173,7 @@ ULONG CDECL ldap_modify_ext_sW( LDAP *ld, WCHAR *dn, LDAPModW **mods, LDAPContro
if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
- if (dn && !(dnU = strWtoU( dn ))) goto exit; + if (!(dnU = dn ? strWtoU( dn ) : strdup( "" ))) goto exit; if (mods && !(modsU = modarrayWtoU( mods ))) goto exit; if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit; if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit; diff --git a/dlls/wldap32/tests/parse.c b/dlls/wldap32/tests/parse.c index 788af6f921c..1653b0ef72c 100644 --- a/dlls/wldap32/tests/parse.c +++ b/dlls/wldap32/tests/parse.c @@ -235,6 +235,66 @@ static void test_ldap_add(void) ldap_unbind( ld ); }
+static void test_ldap_modify(void) +{ + char *one_empty_string[] = { (char *)"", NULL }; + LDAPModA empty_equals_empty = { 0, (char *)"", { one_empty_string } }; + LDAPModA *attrs[] = { &empty_equals_empty, NULL }; + LDAP *ld; + ULONG ret, num; + + ld = ldap_initA( (char *)"db.debian.org", 389 ); + ok( ld != NULL, "ldap_init failed\n" ); + + ret = ldap_modifyA( NULL, NULL, NULL ); + ok( ret == (ULONG)-1, "ldap_modifyA should fail, got %#lx\n", ret ); + ret = ldap_modifyA( NULL, (char *)"", attrs ); + ok( ret == (ULONG)-1, "ldap_modifyA should fail, got %#lx\n", ret ); + ret = ldap_modifyA( ld, NULL, attrs ); + ok( ret != (ULONG)-1, "ldap_modifyA should succeed, got %#lx\n", ret ); + ret = ldap_modifyA( ld, (char *)"", NULL ); + ok( ret != (ULONG)-1, "ldap_modifyA should succeed, got %#lx\n", ret ); + ret = ldap_modifyA( ld, (char *)"", attrs ); + ok( ret != (ULONG)-1, "ldap_modifyA should succeed, got %#lx\n", ret ); + + ret = ldap_modify_sA( NULL, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_modify_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_sA( NULL, (char *)"", attrs ); + ok( ret == LDAP_PARAM_ERROR, "ldap_modify_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_sA( ld, NULL, attrs ); + ok( ret == LDAP_UNDEFINED_TYPE, "ldap_modify_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_sA( ld, (char *)"", NULL ); + ok( ret == LDAP_UNWILLING_TO_PERFORM, "ldap_modify_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_sA( ld, (char *)"", attrs ); + ok( ret == LDAP_UNDEFINED_TYPE, "ldap_modify_sA should fail, got %#lx\n", ret ); + + ret = ldap_modify_extA( NULL, NULL, NULL, NULL, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_modify_extA should fail, got %#lx\n", ret ); + ret = ldap_modify_extA( NULL, (char *)"", attrs, NULL, NULL, &num ); + ok( ret == LDAP_PARAM_ERROR, "ldap_modify_extA should fail, got %#lx\n", ret ); + ret = ldap_modify_extA( ld, NULL, attrs, NULL, NULL, &num ); + ok( !ret, "ldap_modify_extA should succeed, got %#lx\n", ret ); + ret = ldap_modify_extA( ld, (char *)"", NULL, NULL, NULL, &num ); + ok( !ret, "ldap_modify_extA should succeed, got %#lx\n", ret ); + ret = ldap_modify_extA( ld, (char *)"", attrs, NULL, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_modify_extA should fail, got %#lx\n", ret ); + ret = ldap_modify_extA( ld, (char *)"", attrs, NULL, NULL, &num ); + ok( !ret, "ldap_modify_extA should succeed, got %#lx\n", ret ); + + ret = ldap_modify_ext_sA( NULL, NULL, NULL, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_modify_ext_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_ext_sA( NULL, (char *)"", attrs, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_modify_ext_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_ext_sA( ld, NULL, attrs, NULL, NULL ); + ok( ret == LDAP_UNDEFINED_TYPE, "ldap_modify_ext_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_ext_sA( ld, (char *)"", NULL, NULL, NULL ); + ok( ret == LDAP_UNWILLING_TO_PERFORM, "ldap_modify_ext_sA should fail, got %#lx\n", ret ); + ret = ldap_modify_ext_sA( ld, (char *)"", attrs, NULL, NULL ); + ok( ret == LDAP_UNDEFINED_TYPE, "ldap_modify_ext_sA should fail, got %#lx\n", ret ); + + ldap_unbind( ld ); +} + static void test_ldap_server_control( void ) { /* SEQUENCE { INTEGER :: 0x07 } */ @@ -358,6 +418,7 @@ START_TEST (parse) test_ldap_server_control(); test_ldap_bind_sA(); test_ldap_add(); + test_ldap_modify();
ld = ldap_initA( (char *)"db.debian.org", 389 ); ok( ld != NULL, "ldap_init failed\n" );