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

Y2038: Use time_t for commSetConnTimeout() timeout parameter #1492

Closed
wants to merge 8 commits into from

Conversation

kinkie
Copy link
Contributor

@kinkie kinkie commented Sep 24, 2023

Change commSetConnTimeout() "timeout" parameter from int to time_t, to
match the common caller type and improve Year 2038-safety on systems
with 32-bit int.

Detected by Coverity. CID 1545129: Use of 32-bit time_t (Y2K38_SAFETY).

Change the "timeout" parameter to commSetConnTimeout
from int to time_t, to ensure 2032-safety on systems
where int is 32-bit.

Detected by Coverity scan, CID 1545129 "Use of 32-bit time_t"
Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

Thank you for improving this code.

We are using negative commSetConnTimeout() timeout values while time_t is not, technically, guaranteed to be signed. However, this PR can still be considered a step forward even though it does not solve that (unlikely to affect us in real world) problem because nearly all commSetConnTimeout() callers do use time_t already.

src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
src/dns_internal.cc Outdated Show resolved Hide resolved
@rousskov rousskov changed the title commSetConnTimeout: make timeout param a time_t Y2038: Use time_t for commSetConnTimeout() timeout parameter Sep 24, 2023
@rousskov
Copy link
Contributor

I adjusted PR title/description, primarily to fix a few minor technical issues and typos. Please adjust further as needed.

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Sep 24, 2023
@kinkie kinkie added S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box and removed S-waiting-for-author author action is expected (and usually required) labels Sep 25, 2023
@kinkie kinkie requested a review from rousskov September 25, 2023 12:38
src/helper.cc Outdated Show resolved Hide resolved
@kinkie kinkie requested a review from rousskov September 25, 2023 16:11
@rousskov rousskov added M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels and removed S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box labels Sep 25, 2023
@rousskov
Copy link
Contributor

I adjusted PR description again to use the original/shorter version of the Y2K38_SAFETY defect wording. I did not have access to that version earlier because Coverity service was down. Sorry.

@yadij
Copy link
Contributor

yadij commented Sep 25, 2023

RFC: long-term we are better to be moving to the std::chrono types instead of time_t. Is it possible to start that conversion here without major trouble?

@rousskov
Copy link
Contributor

long-term we are better to be moving to the std::chrono types instead of time_t.

Yes, of course.

Is it possible to start that conversion here without major trouble?

I think the answer depends, in part, on whether we want to start supporting sub-second timeouts. I cannot be sure without studying this issue, but I suspect that we do. If we do, then, for commSetConnTimeout(), the migration to std::chrono should probably start at the timeout storing/handling code, not its users (that this PR is focusing on) because while it is possible to safely convert time_t to the right std::chrono type, it is not possible to safely convert any sub-second std::chrono type to time_t.

FWIW, my "use PackableStream to print time_t" suggestions in #1493 (review) and #1494 (review) are tiny steps towards that std::chrono conversion.

squid-anubis pushed a commit that referenced this pull request Sep 26, 2023
Change commSetConnTimeout() "timeout" parameter from int to time_t, to
match the common caller type and improve Year 2038-safety on systems
with 32-bit int.

Detected by Coverity. CID 1545129: Use of 32-bit time_t (Y2K38_SAFETY).
@squid-anubis squid-anubis added the M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels label Sep 26, 2023
@squid-anubis squid-anubis added M-merged https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels labels Sep 27, 2023
@@ -592,7 +592,7 @@ commUnsetFdTimeout(int fd)
}

int
commSetConnTimeout(const Comm::ConnectionPointer &conn, int timeout, AsyncCall::Pointer &callback)
commSetConnTimeout(const Comm::ConnectionPointer &conn, time_t timeout, AsyncCall::Pointer &callback)
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not realize this by looking at the PR diff, but I now see two more problems related to this (merged) PR scope:

  • This function and commUnsetConnTimeout() return type should be time_t rather than int.
  • The C-style timeout cast inside this function should be removed.

@kinkie, if you can fix these problems, please do.

The latest Coverity report (defect 1547031) triggered this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-merged https://github.com/measurement-factory/anubis#pull-request-labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants