Compare commits

..

3 commits

Author SHA1 Message Date
lda
3788d044e6
[FIX] Fix potential double-free issue in Cytoplasm 2023-12-14 18:31:20 +01:00
928e9c8223 Update CHANGELOG.md 2023-12-02 10:26:24 -05:00
lda
17f1a41519 HttpRouter: Decode path parts before matching. (#19)
Required by Telodendria/Telodendria#44.

Reviewed-on: Telodendria/Cytoplasm#19
Co-authored-by: lda <lda@freetards.xyz>
Co-committed-by: lda <lda@freetards.xyz>
2023-12-02 10:25:28 -05:00
2 changed files with 35 additions and 28 deletions

View file

@ -15,6 +15,7 @@ are not even initialized to a default value.
- Fixed a memory leak that would occur in code generated by `j2s` under - Fixed a memory leak that would occur in code generated by `j2s` under
specific circumstances. specific circumstances.
- Added `JsonMerge()` to the JSON API to merge two JSON objects together. - Added `JsonMerge()` to the JSON API to merge two JSON objects together.
- Make `HttpRouter` decode path parts before matching them on regular expressions.
## v0.4.0 ## v0.4.0

View file

@ -23,6 +23,7 @@
*/ */
#include <HttpRouter.h> #include <HttpRouter.h>
#include <Http.h>
#include <Memory.h> #include <Memory.h>
#include <HashMap.h> #include <HashMap.h>
#include <Str.h> #include <Str.h>
@ -228,6 +229,8 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret)
regmatch_t pmatch[REG_MAX_SUB]; regmatch_t pmatch[REG_MAX_SUB];
pathPart = HttpUrlDecode(pathPart);
i = 0; i = 0;
while (HashMapIterateReentrant(node->children, &key, (void **) &val, &i)) while (HashMapIterateReentrant(node->children, &key, (void **) &val, &i))
@ -243,6 +246,7 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret)
if (!val) if (!val)
{ {
exec = NULL; exec = NULL;
Free(pathPart);
break; break;
} }
@ -263,12 +267,14 @@ HttpRouterRoute(HttpRouter * router, char *path, void *args, void **ret)
substr = StrSubstr(pathPart, cpmatch.rm_so, cpmatch.rm_eo); substr = StrSubstr(pathPart, cpmatch.rm_so, cpmatch.rm_eo);
if (pmatch[i].rm_so == -1) if (pmatch[i].rm_so == -1)
{ {
Free(pathPart);
break; break;
} }
ArrayAdd(matches, substr); ArrayAdd(matches, substr);
} }
} }
Free(pathPart);
} }
Free(path); Free(path);
} }