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

Error message using feature timestamp #44

Closed
uggla opened this issue Dec 13, 2021 · 4 comments
Closed

Error message using feature timestamp #44

uggla opened this issue Dec 13, 2021 · 4 comments
Labels
CVE-2020-26235 Unsound behaviour with local timezone access

Comments

@uggla
Copy link

uggla commented Dec 13, 2021

Hello Sam,

I have the following message compiling my program.
I try to activate the threads feature, but I still get the error message below.
Of course, if I disable the timestamp feature, it works.
Could you advise how to fix this issue as it appears unclear to me ?

thread 'main' panicked at 'Could not determine the UTC offset on this system. Possible causes are that the time crate does not implement "local_offset_at" on your system, or that you are running in a multi-threaded environment and the time crate is returning "None" from "local_offset_at" to avoid unsafe behaviour. See the time crate's documentation for more information. (https://time-rs.github.io/internal-api/time/index.html#feature-flags): IndeterminateOffset', /home/uggla/rust/registry/src/github.com-1ecc6299db9ec823/simple_logger-1.15.1/src/lib.rs:360:64
@uggla
Copy link
Author

uggla commented Dec 13, 2021

Ok I think I get it:

/// Obtain the system's UTC offset.
#[cfg(any(target_os = "linux", target_os = "freebsd", unsound_local_offset))]
pub(super) fn local_offset_at(datetime: OffsetDateTime) -> Option<UtcOffset> {
    // Ensure that the process is single-threaded unless the user has explicitly opted out of this
    // check. This is to prevent issues with the environment being mutated by a different thread in
    // the process while execution of this function is taking place, which can cause a segmentation
    // fault by dereferencing a dangling pointer.
    if !cfg!(unsound_local_offset) && num_threads::is_single_threaded() != Some(true) {
        return None;
    }

    // Safety: We have just confirmed that the process is single-threaded or the user has explicitly
    // opted out of soundness.
    let tm = unsafe { timestamp_to_tm(datetime.unix_timestamp()) }?;
    tm_to_offset(tm)
}

https://time-rs.github.io/internal-api/time/sys/local_offset_at/imp/fn.timestamp_to_tm.html

@borntyping
Copy link
Owner

There's some more information on this issue: #43

borntyping added a commit that referenced this issue Dec 14, 2021
This sidesteps issues users are having when using local times in
conditions where the `time` crate cannot safely get the local time.

Thanks to @uggla and @rye.

#44
#43
borntyping added a commit that referenced this issue Dec 14, 2021
This sidesteps issues users are having when using local times in
conditions where the `time` crate cannot safely get the local time.

Thanks to @uggla and @rye.

#44
#43
@borntyping
Copy link
Owner

Released v1.16.0 with options to use UTC timestamps. Thanks!

@borntyping
Copy link
Owner

UTC timestamps are now the default in simple_logger 2.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CVE-2020-26235 Unsound behaviour with local timezone access
Projects
None yet
Development

No branches or pull requests

2 participants