From afc9e0e5dc3389e25c42aba579f792310abcec0d Mon Sep 17 00:00:00 2001 From: LoaD Accumulator Date: Mon, 11 Sep 2023 10:57:16 -0400 Subject: [PATCH 1/2] Fixes issue #33 related to a memory issue, and format some code. (#35) Fixes #33. Co-authored-by: LoaD Accumulator Reviewed-on: https://git.telodendria.io/Telodendria/telodendria/pulls/35 Co-authored-by: LoaD Accumulator Co-committed-by: LoaD Accumulator --- Cytoplasm/src/HttpRouter.c | 8 ++++++-- Cytoplasm/src/Str.c | 1 - src/Routes/RouteUserProfile.c | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cytoplasm/src/HttpRouter.c b/Cytoplasm/src/HttpRouter.c index 87ddae0..bd06c64 100644 --- a/Cytoplasm/src/HttpRouter.c +++ b/Cytoplasm/src/HttpRouter.c @@ -196,7 +196,7 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret) char *pathPart; char *tmp; HttpRouteFunc *exec = NULL; - Array *matches; + Array *matches = NULL; size_t i; int retval; @@ -254,14 +254,18 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret) { /* pmatch[0] is the whole string, not the first * subexpression */ + char * substr; + regmatch_t cpmatch; for (i = 1; i < REG_MAX_SUB; i++) { + cpmatch = pmatch[i]; + substr = StrSubstr(pathPart, cpmatch.rm_so, cpmatch.rm_eo); if (pmatch[i].rm_so == -1) { break; } - ArrayAdd(matches, StrSubstr(pathPart, pmatch[i].rm_so, pmatch[i].rm_eo)); + ArrayAdd(matches, substr); } } } diff --git a/Cytoplasm/src/Str.c b/Cytoplasm/src/Str.c index 98dea0b..2f4c665 100644 --- a/Cytoplasm/src/Str.c +++ b/Cytoplasm/src/Str.c @@ -147,7 +147,6 @@ StrSubstr(const char *inStr, size_t start, size_t end) } len = end - start; - outStr = Malloc(len + 1); if (!outStr) { diff --git a/src/Routes/RouteUserProfile.c b/src/Routes/RouteUserProfile.c index 0c99338..5b795c2 100644 --- a/src/Routes/RouteUserProfile.c +++ b/src/Routes/RouteUserProfile.c @@ -172,7 +172,10 @@ ROUTE_IMPL(RouteUserProfile, path, argp) } finish: ConfigUnlock(config); - Free(username); + + /* Username is handled by the router, freeing it *will* cause issues + * (see #33). I honestly don't know how it didn't come to bite us sooner. + Free(username); */ Free(entry); UserIdFree(userId); UserUnlock(user); From f4cb10804a4baba8d6c59390a7ece66a1f8ea43c Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Mon, 11 Sep 2023 11:01:50 -0400 Subject: [PATCH 2/2] Add change log entry for #35. --- docs/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 15bb2ce..a1b9bf2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -19,6 +19,11 @@ The following endpoints were added: - **POST** `/_matrix/client/v3/user/{userId}/filter` - **GET** `/_matrix/client/v3/user/{userId}/filter/{filterId}` +### Bug Fixes + +- Fixed a double-free in `RouteUserProfile()` that would cause errors with certain +Matrix clients. (#35) + ## v0.3.0 **Saturday, June 10, 2023**