Conversation
There was a problem hiding this comment.
PR Review: Add Validation for S3 Requests After Redirects
Overview
This PR (#519) adds validation logic for S3 requests after redirects occur, focusing particularly on region changes during redirects.
Changes
1. Core Functionality
- Added new function
s3_validate_request_after_redirectto validate if request parameters remain valid after a redirect - The function specifically checks if the region changes during redirect, and handles cleanup appropriately
- Integrated this validation in the stream completion handler (
s3_client_on_stream_complete_fn)
2. Header Updates
- Added the function declaration in
private/s3_request.h
3. Testing
- Added a comprehensive test case
s3_test_client_on_stream_complete_with_redirectto verify the redirect validation works properly - Test covers scenarios involving region changes during redirects
4. CI Configuration
- Updated GitHub workflow configuration to use newer versions of AWS SDK dependencies
Analysis
Strengths
- The changes properly handle an edge case where redirects cause region changes
- Good error handling and cleanup procedures are in place
- Test coverage is provided for the new functionality
- Code follows the existing style and patterns in the codebase
Potential Improvements/Questions
- Could benefit from more detailed comments explaining why region changes during redirects require special handling
- Consider adding a log message when a region change is detected during redirect to help with debugging
Security/Reliability Impact
- Positive impact on reliability by ensuring proper cleanup when redirects change regions
- No apparent security concerns with the implementation
Conclusion
This PR appears to be a solid improvement to the S3 client's redirect handling. It addresses a specific edge case that could potentially cause issues with region changes during redirects. The implementation is well-tested and follows good practices for error handling and resource cleanup.
I would recommend approving this PR after addressing any minor comment improvements mentioned above.
TingDaoK
left a comment
There was a problem hiding this comment.
Comments for PR 519 - Memory Management and Potential Bugs
Lines 8115-8118 - Memory Leak in test_helper Function
The function test_helper allocates a string using aws_s3_tester_build_endpoint_string() but doesn't destroy it in this function. When the function returns the string, it places the responsibility of memory management on the caller. This approach can lead to memory leaks if not clearly documented or if the caller forgets to free the string.
Line 8129 - Memory Leak with hsot_name Variable
The variable hsot_name is assigned a string returned by test_helper() but there's no corresponding call to aws_string_destroy(hsot_name) at the end of the function. This will cause a memory leak. The string needs to be properly destroyed after use.
Lines 8143-8147 - Function Order and Cleanup
There's a potential issue with the cleanup order. The meta request test results are cleaned up before releasing the HTTP message and S3 client. It would be safer to clean up resources in the reverse order of their creation to avoid potential use-after-free issues.
Overall Memory Management Pattern
The function would benefit from a more robust error handling pattern where resources are properly cleaned up even if an operation fails. Currently, if an assertion fails in the middle of the function, resources allocated before the failure point may not be properly released.
AWS_TEST_CASE Declaration
The AWS_TEST_CASE macro is used in an unusual way here compared to the rest of the file. In other parts of the code, the test function is defined first, then registered with AWS_TEST_CASE. Here the registration happens before the function definition, which could lead to confusion or maintenance issues.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #519 +/- ##
=======================================
Coverage 89.70% 89.70%
=======================================
Files 20 20
Lines 6384 6384
=======================================
Hits 5727 5727
Misses 657 657 🚀 New features to boost your workflow:
|
TingDaoK
left a comment
There was a problem hiding this comment.
{
"owner": "awslabs",
"repo": "aws-c-s3",
"pull_number": 519,
"event": "COMMENT",
"body": "Here are my comments on this PR addressing both naming issues and technical concerns:",
"comments": [
{
"path": "tests/s3_data_plane_tests.c",
"position": 8117,
"body": "The helper function `test_helper` has a very generic name that doesn't clearly indicate its purpose. Consider using a more descriptive name that reflects what it does, such as `s_build_test_endpoint_string`."
},
{
"path": "tests/s3_data_plane_tests.c",
"position": 8118,
"body": "**Memory management issue**: This function allocates a string but doesn't handle its destruction, passing that responsibility to the caller. This could lead to memory leaks if not clearly documented or if callers forget to free the string. Consider either adding documentation about memory ownership or implementing a different pattern."
},
{
"path": "tests/s3_data_plane_tests.c",
"position": 8120,
"body": "This test case is defined with `AWS_TEST_CASE(test_s3_default_get, aws_test_s3_default_get)`, but there's already a test with a similar name and functionality (`test_s3_default_get_without_content_length`). Consider clarifying the purpose of this test. Also, the AWS_TEST_CASE registration is placed before the function definition, which is inconsistent with the pattern used in the rest of the file."
},
{
"path": "tests/s3_data_plane_tests.c",
"position": 8129,
"body": "1. There's a typo in the variable name `hsot_name` (should be `host_name`).\n2. **Memory leak**: The string allocated here by `test_helper()` is never freed. You need to add `aws_string_destroy(hsot_name)` before the function returns to prevent a memory leak."
},
{
"path": "tests/s3_data_plane_tests.c",
"position": 8145,
"body": "This test appears to be very similar to the existing `test_s3_default_get_without_content_length` function. Consider refactoring to avoid duplication or clearly document the differences between these tests."
},
{
"path": "tests/s3_data_plane_tests.c",
"position": 8147,
"body": "The cleanup order could be improved. It's a best practice to clean up resources in the reverse order of creation. Consider moving `aws_s3_meta_request_test_results_clean_up` to after releasing the message and client to avoid potential use-after-free issues."
}
]
TingDaoK
left a comment
There was a problem hiding this comment.
Here are my comments on this PR addressing both naming issues and technical concerns:
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.