Author: tfaber Date: Wed May 23 11:54:20 2012 New Revision: 56649
URL: http://svn.reactos.org/svn/reactos?rev=56649&view=rev Log: [RTL] - Use RtlAnsiStringToUnicodeString instead of mbstowcs to correctly handle manifests that aren't null-terminated See issue #6743 for more details.
Modified: trunk/reactos/lib/rtl/actctx.c
Modified: trunk/reactos/lib/rtl/actctx.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/actctx.c?rev=56649&... ============================================================================== --- trunk/reactos/lib/rtl/actctx.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/actctx.c [iso-8859-1] Wed May 23 11:54:20 2012 @@ -1576,13 +1576,17 @@ } else { - /* let's assume utf-8 for now */ - size_t len; - WCHAR *new_buff; + /* TODO: this doesn't handle arbitrary encodings */ + ANSI_STRING xmlA; + UNICODE_STRING xmlW; + + ASSERT(size < MAXUSHORT); + xmlA.Buffer = (PCHAR)buffer; + xmlA.Length = xmlA.MaximumLength = (USHORT)size;
_SEH2_TRY { - len = mbstowcs(NULL, buffer, size); + status = RtlAnsiStringToUnicodeString(&xmlW, &xmlA, TRUE); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -1591,23 +1595,18 @@ } _SEH2_END;
- DPRINT("len = %x\n", len); - - if (len == -1) - { - DPRINT1( "utf-8 conversion failed\n" ); + if (!NT_SUCCESS(status)) + { + DPRINT1("RtlAnsiStringToUnicodeString failed with %lx\n", status); return STATUS_SXS_CANT_GEN_ACTCTX; } - if (!(new_buff = RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY, len))) - return STATUS_NO_MEMORY; - - mbstowcs( new_buff, buffer, size); - xmlbuf.ptr = new_buff; - - xmlbuf.end = xmlbuf.ptr + len / sizeof(WCHAR); + ASSERT(xmlW.Buffer != NULL); + + xmlbuf.ptr = xmlW.Buffer; + xmlbuf.end = xmlbuf.ptr + xmlW.Length / sizeof(WCHAR); status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
- RtlFreeHeap( RtlGetProcessHeap(), 0, new_buff ); + RtlFreeUnicodeString(&xmlW); } return status; }