Skip to content

curlx_now(), prevent zero timestamp - #21034

Closed
icing wants to merge 1 commit into
curl:masterfrom
icing:no-zero-now
Closed

icing wants to merge 1 commit into
curl:masterfrom
icing:no-zero-now

Conversation

@icing

@icing icing commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

As code checks curltime values for zero and interprets this as not-initialized or "forever" in several places, make sure curlx_now() never returns a zero timestamp.

As code checks `curltime` values for zero and interprets this
as not-initialized or "forever" in several places, make sure
`curlx_now()` never returns a zero timestamp.
@testclutch

Copy link
Copy Markdown

Analysis of PR #21034 at 07818a46:

Test 2050 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them).

Generated by Testclutch

@bagder

bagder commented Mar 20, 2026

Copy link
Copy Markdown
Member

Better than #21028 !

@bagder bagder closed this in 5649b21 Mar 21, 2026
outcast36 pushed a commit to greearb/curl that referenced this pull request Jun 3, 2026
As code checks `curltime` values for zero and interprets this
as not-initialized or "forever" in several places, make sure
`curlx_now()` never returns a zero timestamp.

Closes curl#21034
vszakats added a commit to libssh2/libssh2 that referenced this pull request Jul 19, 2026
To honor the actual millisecond timeout set via
`libssh2_session_set_timeout()`, to open the possibility for the same in
other APIs, and to use monotonic time if available.

- add internal abstract time types and macros for handling point in time
  and time intervals, and use them throughout the codebase.
- bump internal abstract time resolution to milliseconds (from seconds).
  Use signed 64-bit integers.
- replace existing millisecond-resolution code in `libssh2_poll()` with
  the internal abstract time interface.
- bump 'now' function to retrieve millisecond-resolution monotonic time
  from the system, if available.

Also:
- append `_s` or `_ms` to public API arguments to tell the time unit.
- keepalive: minor tidy-ups.
- make `ssh2_now()` return at least 1 in the fallback,
  `time(NULL)`-based codepath to not confuse a zero value with unset
  time.
  Credits: Stefan Eissing
  Ref: curl/curl@5649b21
  Ref: curl/curl#21034
- this leaves existing `ssh2_gettimeofday()` (together with its
  Windows-specific local implementation) with a single caller,
  `ssh2_deb_low()`.

Refs:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
https://www.man7.org/linux/man-pages/man3/clock_gettime.3.html
https://pubs.opengroup.org/onlinepubs/009604599/functions/gettimeofday.html
https://www.man7.org/linux/man-pages/man2/gettimeofday.2.html
https://learn.microsoft.com/windows/win32/api/profileapi/nf-profileapi-queryperformancefrequency
https://learn.microsoft.com/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter
https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows

Reported-and-patch-proposal-by: Trzik on github
Based-on-patch-proposals-by: Ryan Kelley
Fixes #1497
Ref: #1818
Closes #1893
Follow-up to 772abc7 #1919

Closes #2341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants