malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.24k stars 31 forks source link

goto :eof in a subroutine makes a heap corruption #88

Closed ghost closed 3 years ago

ghost commented 3 years ago

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: https://github.com/malxau/yori/blob/41640e18b9ee991666ef0ac68aaa902a15c41404/builtins/ys.c#L314-L326

malxau commented 3 years ago

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;
malxau commented 3 years ago

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