diff --git a/xtldr/textui.c b/xtldr/textui.c index a2a6aad..c9aacef 100644 --- a/xtldr/textui.c +++ b/xtldr/textui.c @@ -1182,19 +1182,34 @@ VOID BlpDrawDialogMessage(IN PXTBL_DIALOG_HANDLE Handle, IN PWCHAR Message) { - PWCHAR MsgLine, LastMsgLine; - SIZE_T Index, Length; + PWCHAR Msg, MsgLine, LastMsgLine; + SIZE_T Index, Length, LineLength; + EFI_STATUS Status; ULONG Line; + /* Allocate memory for dialog box message */ + Length = RtlWideStringLength(Message, 0); + Status = BlMemoryAllocatePool(Length * sizeof(WCHAR), (PVOID *)&Msg); + if(Status != STATUS_EFI_SUCCESS) + { + /* Memory allocation failure, print debug message and return */ + BlDebugPrint(L"ERROR: Memory allocation failure (Status Code: 0x%lx)\n", Status); + return; + } + + /* Make a copy of dialog box message */ + RtlCopyMemory(Msg, Message, Length * sizeof(WCHAR)); + Msg[Length] = 0; + /* Tokenize dialog box message */ - MsgLine = RtlTokenizeWideString(Message, L"\n", &LastMsgLine); + MsgLine = RtlTokenizeWideString(Msg, L"\n", &LastMsgLine); /* Iterate through message lines */ Line = 0; while(MsgLine) { /* Determine line length */ - Length = RtlWideStringLength(Message, 0); + LineLength = RtlWideStringLength(MsgLine, 0); /* Write line in the dialog box */ BlSetCursorPosition(Handle->PosX + 2, Handle->PosY + 2 + Line); @@ -1202,10 +1217,10 @@ BlpDrawDialogMessage(IN PXTBL_DIALOG_HANDLE Handle, BlConsolePrint(L"%S", MsgLine); /* Check if message line is shorter than the dialog box working area */ - if(Length < Handle->Width - 4) + if(LineLength < Handle->Width - 4) { /* Fill the rest of the line with spaces */ - for(Index = Length; Index < Handle->Width - 4; Index++) + for(Index = LineLength; Index < Handle->Width - 4; Index++) { BlConsolePrint(L" "); }