[PATCH] Cygwin: clock_settime: fail with EINVAL if tv_nsec is negative
Christian Franke
Christian.Franke@t-online.de
Thu May 1 12:29:55 GMT 2025
Jon Turney wrote:
> On 30/04/2025 12:33, Christian Franke wrote:
>> Christian Franke wrote:
>>> Jon Turney wrote:
>>>> On 28/04/2025 16:43, Christian Franke wrote:
>>>>> A followup to:
>>>>> https://sourceware.org/pipermail/cygwin-patches/2025q2/013678.html
>>>>
>>>> Thanks!
>>>>
>>>> The SUS page for clock_settime() contains the following text:
>>>>
>>>>> [EINVAL]
>>>>> The tp argument specified a nanosecond value less than zero or
>>>>> greater than or equal to 1000 million.
>>>>
>>>> ... so if we're going to validate tv_nsec, it seems that's the
>>>> range to use
>>>>
>>>>
>>>
>>> Yes. The patch only checks the lower bound because the upper bound
>>> is already correctly checked later in settimeofday().
>
> This is just prompts me to further questions: Is settimeofday()
> specified to permit some kinds of non-normalized values?
settimeofday() is not part of POSIX, Linux settimeofday(2) only says:
"
EINVAL
Timezone (or something else) is invalid.
"
It is also usually missing in the docs that negative time_t values are
accepted by gmtime() etc. This works on Cygwin and Debian:
$ date -u -d '0000-01-01' +%s
-62167219200
$ date -u -d @-62167219200 -Is
0000-01-01T00:00:00+00:00
More information about the Cygwin-patches
mailing list