cinera.c: Fix stack-use-after-return segfault

The ClashResolver, or a memory_book variable therein, triggered a
stack-use-after-return segfault. Fixed by initialising the ClashResolver
in main() and passing it to InitClashResolver() by pointer, rather than
initialising it in InitClashResolver().
This commit is contained in:
Matt Mascarenhas 2024-03-12 13:03:08 +00:00
parent 213bb2f882
commit 14dafa4abe
1 changed files with 14 additions and 15 deletions

View File

@ -23,7 +23,7 @@ typedef struct
version CINERA_APP_VERSION = { version CINERA_APP_VERSION = {
.Major = 0, .Major = 0,
.Minor = 10, .Minor = 10,
.Patch = 29 .Patch = 30
}; };
#define __USE_XOPEN2K8 // NOTE(matt): O_NOFOLLOW #define __USE_XOPEN2K8 // NOTE(matt): O_NOFOLLOW
@ -903,8 +903,8 @@ FreeBook(memory_book *M)
void void
FreeAndReinitialiseBook(memory_book *M) FreeAndReinitialiseBook(memory_book *M)
{ {
int PageSize = M->PageSize; uint64_t PageSize = M->PageSize;
int DataWidthInBytes = M->DataWidthInBytes; uint64_t DataWidthInBytes = M->DataWidthInBytes;
FreeBook(M); FreeBook(M);
@ -4783,18 +4783,16 @@ typedef struct
bool Resolving; bool Resolving;
} clash_resolver; } clash_resolver;
clash_resolver void
InitClashResolver(void) InitClashResolver(clash_resolver *ClashResolver)
{ {
clash_resolver Result = {}; ClashResolver->Book[0] = InitBook(sizeof(clash_entry), 8);
Result.Book[0] = InitBook(sizeof(clash_entry), 8); ClashResolver->Book[1] = InitBook(sizeof(clash_entry), 8);
Result.Book[1] = InitBook(sizeof(clash_entry), 8); ClashResolver->Main = &ClashResolver->Book[0];
Result.Main = &Result.Book[0]; ClashResolver->Holder = &ClashResolver->Book[1];
Result.Holder = &Result.Book[1]; ClashResolver->Chain = InitBookOfPointers(8);
Result.Chain = InitBookOfPointers(8); ClashResolver->ChainStructure = CS_OPEN_ENDED;
Result.ChainStructure = CS_OPEN_ENDED; ClashResolver->Resolving = FALSE;
Result.Resolving = FALSE;
return Result;
} }
void void
@ -18325,7 +18323,8 @@ main(int ArgC, char **Args)
CollationBuffers.Search.ID = BID_COLLATION_BUFFERS_SEARCH; // NOTE(matt): Allocated by SearchToBuffer() CollationBuffers.Search.ID = BID_COLLATION_BUFFERS_SEARCH; // NOTE(matt): Allocated by SearchToBuffer()
memory_book TokensList = InitBook(sizeof(tokens), 8); memory_book TokensList = InitBook(sizeof(tokens), 8);
clash_resolver ClashResolver = InitClashResolver(); clash_resolver ClashResolver = {};
InitClashResolver(&ClashResolver);
template BespokeTemplate = {}; template BespokeTemplate = {};
neighbourhood Neighbourhood = {}; neighbourhood Neighbourhood = {};