From 124e90d9e54f8d6385827a656ed2ddf8bc788d54 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Fri, 24 Mar 2023 10:09:09 -0600 Subject: [PATCH] wldap32: Handle null DN or null message in ldap_delete* and add tests. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54702 --- dlls/wldap32/delete.c | 8 ++++---- dlls/wldap32/tests/parse.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/dlls/wldap32/delete.c b/dlls/wldap32/delete.c index b085142d83d..8539b7266eb 100644 --- a/dlls/wldap32/delete.c +++ b/dlls/wldap32/delete.c @@ -72,7 +72,7 @@ ULONG CDECL ldap_delete_extA( LDAP *ld, char *dn, LDAPControlA **serverctrls, LD TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), serverctrls, clientctrls, message ); - if (!ld) return WLDAP32_LDAP_PARAM_ERROR; + if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR; if (dn && !(dnW = strAtoW( dn ))) goto exit; if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit; @@ -99,9 +99,9 @@ ULONG CDECL ldap_delete_extW( LDAP *ld, WCHAR *dn, LDAPControlW **serverctrls, L TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), serverctrls, clientctrls, message ); - if (!ld) return WLDAP32_LDAP_PARAM_ERROR; + if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR; - if (dn && !(dnU = strWtoU( dn ))) goto exit; + if (!(dnU = dn ? strWtoU( dn ) : strdup( "" ))) goto exit; if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit; if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit; else @@ -155,7 +155,7 @@ ULONG CDECL ldap_delete_ext_sW( LDAP *ld, WCHAR *dn, LDAPControlW **serverctrls, if (!ld) return WLDAP32_LDAP_PARAM_ERROR; - if (dn && !(dnU = strWtoU( dn ))) goto exit; + if (!(dnU = dn ? strWtoU( dn ) : strdup( "" ))) goto exit; if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit; if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit; else diff --git a/dlls/wldap32/tests/parse.c b/dlls/wldap32/tests/parse.c index f5af100ca60..19e7a48b471 100644 --- a/dlls/wldap32/tests/parse.c +++ b/dlls/wldap32/tests/parse.c @@ -349,6 +349,33 @@ static void test_ldap_compare( LDAP *ld ) ok( ret == LDAP_UNDEFINED_TYPE, "ldap_compare_ext_sA should fail, got %#lx\n", ret ); } +static void test_ldap_delete( LDAP *ld ) +{ + ULONG ret, num; + + ret = ldap_deleteA( NULL, NULL ); + ok( ret == (ULONG)-1, "ldap_deleteA should fail, got %#lx\n", ret ); + ret = ldap_deleteA( NULL, (char *)"" ); + ok( ret == (ULONG)-1, "ldap_deleteA should fail, got %#lx\n", ret ); + + ret = ldap_delete_sA( NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_delete_sA should fail, got %#lx\n", ret ); + ret = ldap_delete_sA( NULL, (char *)"" ); + ok( ret == LDAP_PARAM_ERROR, "ldap_delete_sA should fail, got %#lx\n", ret ); + + ret = ldap_delete_extA( NULL, NULL, NULL, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_delete_extA should fail, got %#lx\n", ret ); + ret = ldap_delete_extA( NULL, (char *)"", NULL, NULL, &num ); + ok( ret == LDAP_PARAM_ERROR, "ldap_delete_extA should fail, got %#lx\n", ret ); + ret = ldap_delete_extA( ld, (char *)"", NULL, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_delete_extA should fail, got %#lx\n", ret ); + + ret = ldap_delete_ext_sA( NULL, NULL, NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_delete_ext_sA should fail, got %#lx\n", ret ); + ret = ldap_delete_ext_sA( NULL, (char *)"", NULL, NULL ); + ok( ret == LDAP_PARAM_ERROR, "ldap_delete_ext_sA should fail, got %#lx\n", ret ); +} + static void test_ldap_server_control( void ) { /* SEQUENCE { INTEGER :: 0x07 } */ @@ -478,6 +505,7 @@ START_TEST (parse) test_ldap_add( ld ); test_ldap_modify( ld ); test_ldap_compare( ld ); + test_ldap_delete( ld ); test_ldap_parse_sort_control( ld ); test_ldap_search_extW( ld ); test_ldap_get_optionW( ld ); -- 2.11.4.GIT