malxau/yori

goto :eof in a subroutine makes a heap corruption

Closed this issue · 2 comments

This code:

call test
goto :eof

:test
goto :eof

Makes Yori crash with exit code 3221226356(A heap has been corrupted.)
In CMD this does the same as exit /b 0 and Yori's return 0
Probably something with this code:

yori/builtins/ys.c

Lines 314 to 326 in 41640e1

VOID
YsGotoScriptEnd(VOID)
{
PYORI_LIST_ENTRY ListEntry;
PYS_SCRIPT_LINE Line;
ListEntry = YoriLibGetPreviousListEntry(&YsActiveScript->LineLinks, NULL);
ASSERT(ListEntry != NULL);
if (ListEntry != NULL) {
Line = CONTAINING_RECORD(ListEntry, YS_SCRIPT_LINE, LineLinks);
YsActiveScript->ActiveLine = Line;
}
}

Thanks for the report. I think it's just that I don't remember my own conventions. It's trying to iterate through all open subroutine contexts and free them, but to do that it needs to specify the list head to know when to terminate (as opposed to any arbitrary list element where it will return the list head as a valid element.)

diff --git a/builtins/ys.c b/builtins/ys.c
index 4552ad3..68c0669 100644
--- a/builtins/ys.c
+++ b/builtins/ys.c
@@ -1195,7 +1195,7 @@ YsFreeScript(
     NextEntry = YoriLibGetNextListEntry(&Script->CallStackLinks, NULL);
     while(NextEntry != NULL) {
         StackLocation = CONTAINING_RECORD(NextEntry, YS_CALL_STACK, StackLinks);
-        NextEntry = YoriLibGetNextListEntry(&StackLocation->StackLinks, NextEntry);
+        NextEntry = YoriLibGetNextListEntry(&Script->CallStackLinks, NextEntry);

         YsFreeCallStack(StackLocation);
         CallStackFound = TRUE;

This should be fixed in 1.50, released today. Please let me know if there are further related issues.