Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid overflowing pointers passed to memcpy #874

Merged
merged 3 commits into from
May 20, 2024

Conversation

qinheping
Copy link
Contributor

@qinheping qinheping commented Dec 6, 2021

After executing the for-loop in aws_array_list_mem_swap, the pointers item1 and item2 could be one past the boundaries. Therefore, both pointers could be outside the address space of the program and result in undefined behavior according to the C99 as follows (7.21.1 par 2):

Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4..

Issue: diffblue/cbmc#6472.

Description of changes: stop calling memcpy if the remainder is zero.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me given the description. It is low risk, high reward.

source/array_list.c Show resolved Hide resolved
@yasminetalby yasminetalby added the needs-review This issue or pull request needs review from a core team member. label Jul 6, 2023
@graebm graebm enabled auto-merge (squash) May 20, 2024 22:12
@graebm graebm merged commit ce899b9 into awslabs:main May 20, 2024
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cbmc Anything related to CBMC proofs. needs-review This issue or pull request needs review from a core team member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants