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

Replace chrono with time (address RUSTSEC-2020-0071) #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jeff-hiner
Copy link

@jeff-hiner jeff-hiner commented Jan 26, 2023

This library is unfortunately more susceptible than normal to the env var race conditions in the RUSTSEC, because it uses local time calls extensively.

This PR addresses the vulnerability by replacing chrono with time 0.3. This is a semver breaking change, because it touches quite a few public interfaces.

@jssblck
Copy link

jssblck commented Mar 2, 2023

@kevinhoffman is there anything blocking this from being merged and released? Would be happy to help if I can.

@jeff-hiner
Copy link
Author

Bump?

@adrianbenavides
Copy link

Any update on this @kevinhoffman? Would be awesome to have this so we can use this crate in projects where we enforce cargo deny passing.

@keehun
Copy link

keehun commented Oct 9, 2023

I want to ➕ what others' have been asking for: any update on getting this merged?

@@ -313,8 +308,8 @@ where
RC: RollingCondition,
{
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
let now = Local::now();
self.write_with_datetime(buf, &now)
let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
Copy link

Choose a reason for hiding this comment

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

FYI: This change can introduce a memory leak due to time-rs/time#651

Copy link
Author

Choose a reason for hiding this comment

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

A mach ports leak is better than a segfault, but this is something best addressed via a PR to the num_threads crate.

Copy link

Choose a reason for hiding this comment

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

This is called quite frequently and every call will leak at least numberOfThreads mach ports. This can easily accumulate to several GB of leaked memory for long-running processes like daemons.

It's also worth pointing out that OffsetDateTime::now_local() will always fail for macOS (unless the process is single threaded). Which makes this equivalent to let now = OffsetDateTime::now_utc(); (on Apple platforms).
It might make sense to consider rotating based on UTC instead of local time in general. This would save quite a few CPU cycles and it's what would happen on Apple platforms with the suggested code anyway.

Copy link
Author

Choose a reason for hiding this comment

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

I think rotating on UTC is a totally acceptable solution. I'm happy to modify the PR, but I haven't heard anything from the maintainer in over a year so I'm not sure if the crate is still being maintained.

@pitdicker
Copy link

Out of curiosity. Since version 0.4.30 chrono no longer depends on time 0.1 (https://github.com/chronotope/chrono/releases/tag/v0.4.30). And before that it didn't use the code that was vulnerable to RUSTSEC-2020-0071 since chrono 4.20.
Would this change still be needed?

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.

6 participants