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 buffer overflow on invalid DateTime #186

Merged
merged 1 commit into from
Aug 6, 2020

Conversation

edgar-bonet
Copy link
Contributor

The timestamp() method overflows its internal buffer if any of the data fields of the provided DateTime (save for yOff) is larger than 99. Such DateTime objects are all invalid. This pull request makes the method safe for any DateTime, whether it is valid or not.

Although it is understood that nothing meaningful should be expected out of invalid data, corrupting memory should always be avoided. The rationale is that it is fine for operations on invalid data to yield unspecified (i.e. meaningless) results, but undefined behavior (i.e. anything can happen, including a crash) should always be avoided.

Incidentally, the patched timestamp() method happens to return a meaningful representation, even for invalid DateTime objects: it exposes the contents of the object members. This turned out to be useful for testing the proposed fixDateTime() method, from pull request #185.

The timestamp() method would overflow its internal buffer if any of the
data fields of the provided DateTime (save for yOff) was larger than 99.
Even though any such DateTime would be invalid, it should not corrupt
the memory.
@drak7 drak7 merged commit f972825 into adafruit:master Aug 6, 2020
@edgar-bonet edgar-bonet deleted the invalid-ovf branch August 6, 2020 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants