harden session parsing/validation and read_file bounds with regressio…#25
Open
pavankumar464 wants to merge 2 commits into
Open
harden session parsing/validation and read_file bounds with regressio…#25pavankumar464 wants to merge 2 commits into
pavankumar464 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to harden session cookie parsing/validation and improve read_file() robustness, with new regression tests exercising those edge cases.
Changes:
- Add regression tests for
read_file()directory input handling and session cookie parsing behaviors. - Tighten session ID parsing to avoid
strtok()mutation and validate prefix/length/charset more strictly. - Add error handling around
fseek()/ftell()inread_file().
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/parser_test.cpp |
Adds new regression tests for read_file() and session cookie parsing behaviors. |
tests/CMakeLists.txt |
Links jst_session.c into the test binary so session tests can execute. |
source/jst_session.c |
Hardens session ID extraction/validation from HTTP_COOKIE and avoids modifying cookie memory. |
source/jst_internal.c |
Adds error checks for file positioning calls in read_file(). |
Comments suppressed due to low confidence (1)
source/jst_internal.c:171
read_file()returns early on failure without initializing*bufout/*lenout. Callers (and the new regression test) rely on these being left as NULL/0, but that currently depends on the caller pre-initializing them. Initialize outputs at the start of the function to make the API safer and deterministic on error paths.
int read_file(const char *filename, char** bufout, size_t* lenout)
{
FILE* pf;
size_t size;
long tell_result;
size_t rc;
char* buf;
CosaPhpExtLog( "read_file %s\n", filename );
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…n tests