From d4d3bacac44334772863057dba792ab75d0bf7f4 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 23 Nov 2015 12:56:39 +0300 Subject: [PATCH] wldap32: Properly implement ldap_encode_sort_control[A, W] (Coverity). Signed-off-by: Nikolay Sivov Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/wldap32/control.c | 40 ++++++++++++++++++++++++++++++++++++---- dlls/wldap32/wldap32.h | 13 +++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/dlls/wldap32/control.c b/dlls/wldap32/control.c index b0c9102a1ed..b9d7b3b8f53 100644 --- a/dlls/wldap32/control.c +++ b/dlls/wldap32/control.c @@ -274,15 +274,37 @@ INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info, return ret; } +static inline void bv_val_dup( const struct WLDAP32_berval *src, struct WLDAP32_berval *dst ) +{ + dst->bv_val = HeapAlloc( GetProcessHeap(), 0, src->bv_len ); + if (dst->bv_val) + { + memcpy( dst->bv_val, src->bv_val, src->bv_len ); + dst->bv_len = src->bv_len; + } + else + dst->bv_len = 0; +} + /*********************************************************************** * ldap_encode_sort_controlA (WLDAP32.@) * * See ldap_encode_sort_controlW. */ ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkeys, - PLDAPControlA control, BOOLEAN critical ) + PLDAPControlA ret, BOOLEAN critical ) { - return ldap_create_sort_controlA( ld, sortkeys, critical, &control ); + LDAPControlA *control; + ULONG result; + + if ((result = ldap_create_sort_controlA( ld, sortkeys, critical, &control )) == WLDAP32_LDAP_SUCCESS) + { + ret->ldctl_oid = strdupU(control->ldctl_oid); + bv_val_dup( &control->ldctl_value, &ret->ldctl_value ); + ret->ldctl_iscritical = control->ldctl_iscritical; + ldap_control_freeA( control ); + } + return result; } /*********************************************************************** @@ -308,9 +330,19 @@ ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkeys * ldap_create_sort_control instead. */ ULONG CDECL ldap_encode_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkeys, - PLDAPControlW control, BOOLEAN critical ) + PLDAPControlW ret, BOOLEAN critical ) { - return ldap_create_sort_controlW( ld, sortkeys, critical, &control ); + LDAPControlW *control; + ULONG result; + + if ((result = ldap_create_sort_controlW( ld, sortkeys, critical, &control )) == WLDAP32_LDAP_SUCCESS) + { + ret->ldctl_oid = strdupW(control->ldctl_oid); + bv_val_dup( &control->ldctl_value, &ret->ldctl_value ); + ret->ldctl_iscritical = control->ldctl_iscritical; + ldap_control_freeW( control ); + } + return result; } /*********************************************************************** diff --git a/dlls/wldap32/wldap32.h b/dlls/wldap32/wldap32.h index 00a85a36539..55852a66170 100644 --- a/dlls/wldap32/wldap32.h +++ b/dlls/wldap32/wldap32.h @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "wine/unicode.h" + extern HINSTANCE hwldap32 DECLSPEC_HIDDEN; ULONG map_error( int ) DECLSPEC_HIDDEN; @@ -37,6 +39,17 @@ static inline char *strdupU( const char *src ) return dst; } +static inline WCHAR *strdupW( const WCHAR *src ) +{ + WCHAR *dst; + + if (!src) return NULL; + dst = HeapAlloc( GetProcessHeap(), 0, (strlenW( src ) + 1) * sizeof(WCHAR) ); + if (dst) + strcpyW( dst, src ); + return dst; +} + static inline LPWSTR strAtoW( LPCSTR str ) { LPWSTR ret = NULL;