http_aws_sigv4: Fix invalid compare function handling zero-length pairs #15778
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.
The compare_func() can violate the antisymmetric property required by qsort. Specifically, when both aa->len == 0 and bb->len == 0, the function returns conflicting results (-1 for compare_func(a, b) and -1 for compare_func(b, a)).
This violates the rules of qsort and may lead to undefined behavior, including incorrect sorting or memory corruption in glibc [1].
Add a check to return 0 when both lengths are zero, ensuring proper behavior and preventing undefined behavior in the sorting process.
Ref: https://www.qualys.com/2024/01/30/qsort.txt [1]