- Use RtlAnsiStringToUnicodeString instead of mbstowcs to correctly handle manifests that aren't null-terminated
See issue #6743 for more details.

svn path=/trunk/; revision=56649
This commit is contained in:
Thomas Faber 2012-05-23 11:54:20 +00:00
parent c43df67bd6
commit 25d5ac32b6

View file

@ -1576,13 +1576,17 @@ static NTSTATUS parse_manifest( struct actctx_loader* acl, struct assembly_ident
} }
else else
{ {
/* let's assume utf-8 for now */ /* TODO: this doesn't handle arbitrary encodings */
size_t len; ANSI_STRING xmlA;
WCHAR *new_buff; UNICODE_STRING xmlW;
ASSERT(size < MAXUSHORT);
xmlA.Buffer = (PCHAR)buffer;
xmlA.Length = xmlA.MaximumLength = (USHORT)size;
_SEH2_TRY _SEH2_TRY
{ {
len = mbstowcs(NULL, buffer, size); status = RtlAnsiStringToUnicodeString(&xmlW, &xmlA, TRUE);
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -1591,23 +1595,18 @@ static NTSTATUS parse_manifest( struct actctx_loader* acl, struct assembly_ident
} }
_SEH2_END; _SEH2_END;
DPRINT("len = %x\n", len); if (!NT_SUCCESS(status))
if (len == -1)
{ {
DPRINT1( "utf-8 conversion failed\n" ); DPRINT1("RtlAnsiStringToUnicodeString failed with %lx\n", status);
return STATUS_SXS_CANT_GEN_ACTCTX; return STATUS_SXS_CANT_GEN_ACTCTX;
} }
if (!(new_buff = RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY, len))) ASSERT(xmlW.Buffer != NULL);
return STATUS_NO_MEMORY;
mbstowcs( new_buff, buffer, size); xmlbuf.ptr = xmlW.Buffer;
xmlbuf.ptr = new_buff; xmlbuf.end = xmlbuf.ptr + xmlW.Length / sizeof(WCHAR);
xmlbuf.end = xmlbuf.ptr + len / sizeof(WCHAR);
status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf ); status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
RtlFreeHeap( RtlGetProcessHeap(), 0, new_buff ); RtlFreeUnicodeString(&xmlW);
} }
return status; return status;
} }