Fix heap corruptions and memory leaks in dnsapi

Patch by Samuel Serapión with some modifications by me after discussing it with Art Yerkes

See issue #3387 for more details.

svn path=/trunk/; revision=34297
This commit is contained in:
Colin Finck 2008-07-04 21:51:54 +00:00
parent b82fda4139
commit 458e927317
3 changed files with 16 additions and 8 deletions

View file

@ -46,6 +46,12 @@ DNS_STATUS WINAPI DnsAcquireContextHandle_W
/* For now, don't worry about the user's identity. */ /* For now, don't worry about the user's identity. */
Context = (PWINDNS_CONTEXT)RtlAllocateHeap( RtlGetProcessHeap(), 0, Context = (PWINDNS_CONTEXT)RtlAllocateHeap( RtlGetProcessHeap(), 0,
sizeof( WINDNS_CONTEXT ) ); sizeof( WINDNS_CONTEXT ) );
if(!Context){
*ContextHandle = 0;
return ERROR_OUTOFMEMORY;
}
/* The real work here is to create an adns_state that will help us /* The real work here is to create an adns_state that will help us
* do what we want to later. */ * do what we want to later. */
adns_status = adns_init( &Context->State, adns_status = adns_init( &Context->State,
@ -55,6 +61,7 @@ DNS_STATUS WINAPI DnsAcquireContextHandle_W
0 ); 0 );
if( adns_status != adns_s_ok ) { if( adns_status != adns_s_ok ) {
*ContextHandle = 0; *ContextHandle = 0;
RtlFreeHeap( RtlGetProcessHeap(), 0, Context );
return DnsIntTranslateAdnsToDNS_STATUS( adns_status ); return DnsIntTranslateAdnsToDNS_STATUS( adns_status );
} else { } else {
*ContextHandle = (HANDLE)Context; *ContextHandle = (HANDLE)Context;
@ -115,3 +122,4 @@ void WINAPI DnsReleaseContextHandle
RtlFreeHeap( RtlGetProcessHeap(), 0, Context ); RtlFreeHeap( RtlGetProcessHeap(), 0, Context );
} }

View file

@ -145,7 +145,7 @@ DNS_STATUS WINAPI DnsValidateName_UTF8
sizeof( WCHAR ) * (StrLenWc + 1) ); sizeof( WCHAR ) * (StrLenWc + 1) );
mbstowcs( Buffer, Name, StrLenWc + 1 ); mbstowcs( Buffer, Name, StrLenWc + 1 );
Status = DnsValidateName_W( Buffer, Format ); Status = DnsValidateName_W( Buffer, Format );
RtlFreeHeap( GetProcessHeap(), 0, Buffer ); RtlFreeHeap( RtlGetProcessHeap(), 0, Buffer );
return Status; return Status;
} }

View file

@ -102,14 +102,14 @@ DNS_STATUS WINAPI DnsQuery_A
if( adns_error != adns_s_ok ) { if( adns_error != adns_s_ok ) {
adns_finish( astate ); adns_finish( astate );
if ( CurrentName != Name ) { if ( CurrentName != Name ) {
RtlFreeHeap( CurrentName, 0, GetProcessHeap() ); RtlFreeHeap( RtlGetProcessHeap(), 0, CurrentName );
} }
return DnsIntTranslateAdnsToDNS_STATUS( adns_error ); return DnsIntTranslateAdnsToDNS_STATUS( adns_error );
} }
if( answer && answer->rrs.addr ) { if( answer && answer->rrs.addr ) {
if ( CurrentName != Name ) { if ( CurrentName != Name ) {
RtlFreeHeap( CurrentName, 0, GetProcessHeap() ); RtlFreeHeap( RtlGetProcessHeap(), 0, CurrentName );
} }
*QueryResultSet = *QueryResultSet =
(PDNS_RECORD)RtlAllocateHeap( RtlGetProcessHeap(), 0, (PDNS_RECORD)RtlAllocateHeap( RtlGetProcessHeap(), 0,
@ -132,12 +132,12 @@ DNS_STATUS WINAPI DnsQuery_A
NULL == answer->cname ) { NULL == answer->cname ) {
adns_finish( astate ); adns_finish( astate );
if ( CurrentName != Name ) { if ( CurrentName != Name ) {
RtlFreeHeap( CurrentName, 0, GetProcessHeap() ); RtlFreeHeap( RtlGetProcessHeap(), 0, CurrentName );
} }
return ERROR_FILE_NOT_FOUND; return ERROR_FILE_NOT_FOUND;
} }
if ( CurrentName != Name ) { if ( CurrentName != Name ) {
RtlFreeHeap( CurrentName, 0, GetProcessHeap() ); RtlFreeHeap( RtlGetProcessHeap(), 0, CurrentName );
} }
CurrentName = xstrsave( answer->cname ); CurrentName = xstrsave( answer->cname );
if ( NULL == CurrentName ) { if ( NULL == CurrentName ) {
@ -146,7 +146,7 @@ DNS_STATUS WINAPI DnsQuery_A
} }
} }
adns_finish( astate ); adns_finish( astate );
RtlFreeHeap( CurrentName, 0, GetProcessHeap() ); RtlFreeHeap( RtlGetProcessHeap(), 0, CurrentName );
return ERROR_FILE_NOT_FOUND; return ERROR_FILE_NOT_FOUND;
default: default:
return ERROR_OUTOFMEMORY; /* XXX arty: find a better error code. */ return ERROR_OUTOFMEMORY; /* XXX arty: find a better error code. */
@ -298,8 +298,8 @@ DNS_STATUS WINAPI DnsQuery_UTF8
PIP4_ARRAY Servers, PIP4_ARRAY Servers,
PDNS_RECORD *QueryResultSet, PDNS_RECORD *QueryResultSet,
PVOID *Reserved ) { PVOID *Reserved ) {
return DnsQuery_UTF8( Name, Type, Options, Servers, QueryResultSet, UNIMPLEMENTED;
Reserved ); return ERROR_OUTOFMEMORY;
} }
void DnsIntFreeRecordList( PDNS_RECORD ToDelete ) { void DnsIntFreeRecordList( PDNS_RECORD ToDelete ) {