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

gettimeofday implementation for MSVC cannot handle dates beyond 2038 #1076

Open
LainOTN2 opened this issue Aug 2, 2024 · 4 comments · May be fixed by #1078
Open

gettimeofday implementation for MSVC cannot handle dates beyond 2038 #1076

LainOTN2 opened this issue Aug 2, 2024 · 4 comments · May be fixed by #1078
Assignees

Comments

@LainOTN2
Copy link

LainOTN2 commented Aug 2, 2024

MSVC gettimeofday implementation rely on the definition of timeval provided by winsock2.h
https://learn.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-timeval

typedef struct timeval {
long tv_sec;
long tv_usec;
} TIMEVAL, *PTIMEVAL, *LPTIMEVAL;

this give us potential errors when dealing with dates bigger than the year 2038, i.e. OpenSSH-Portable hangs if the machine date is set to a year bigger than 2039

Connection is stuck when time on SSH Server is set after the Year-2038 Problem

@botovq
Copy link
Contributor

botovq commented Aug 2, 2024

Thanks. Looks like that would need some compat implementation of gettimeofday via GetSystemTime and SystemTimeToFileTime or something like that.

Would be nice if the OS provided a fix on the system level rather than requiring downstreams to come up with workarounds for its brokenness...

@LainOTN2
Copy link
Author

LainOTN2 commented Aug 2, 2024

The funcion is already compat implemented here:

int gettimeofday(struct timeval * tp, struct timezone * tzp)

but when declaring

int gettimeofday(struct timeval *tp, void *tzp);

we are taking the timeval declaration from winsock2.h, that is a signed 32 bits.

@botovq
Copy link
Contributor

botovq commented Aug 2, 2024

Right. I need to fix the aggressive .gitignore...

If we're lucky, the diff below works. I'm unsure how posix_win.c ends up pulling in sys/time.h, perhaps it needs an explicit such include somewhere at the top.

diff --git a/include/compat/sys/time.h b/include/compat/sys/time.h
index 76428c1..2448969 100644
--- a/include/compat/sys/time.h
+++ b/include/compat/sys/time.h
@@ -8,6 +8,15 @@
 
 #ifdef _MSC_VER
 #include <winsock2.h>
+
+#define timeval libressl_timeval
+#define gettimeofday libressl_gettimeofday
+
+struct timeval {
+	long long	tv_sec;
+	long		tv_usec;
+};
+
 int gettimeofday(struct timeval *tp, void *tzp);
 #else
 #include_next <sys/time.h>

@botovq botovq linked a pull request Aug 2, 2024 that will close this issue
@botovq
Copy link
Contributor

botovq commented Aug 2, 2024

See #1078. It would be great if you could check if this addresses the issue.

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 a pull request may close this issue.

3 participants