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

[runtime] Fix potential overflow when using mono_msec_ticks #2721

Merged
merged 2 commits into from Apr 25, 2016

Conversation

luhenry
Copy link
Contributor

@luhenry luhenry commented Mar 4, 2016

No description provided.

@luhenry
Copy link
Contributor Author

luhenry commented Mar 4, 2016

@alexrp @kumpera could you please review? Thank you

@alexrp
Copy link
Contributor

alexrp commented Mar 4, 2016

For the case in mono-proclib.c, couldn't we have a mono_msec_boottime64 implemented in terms of GetTickCount64 on Windows and get_boot_time (static function already in mono-time.c) on Unix?

@alexrp
Copy link
Contributor

alexrp commented Mar 4, 2016

Sorry, not in terms of get_boot_time on Unix, but doing something similar to what it's doing to get the uptime value.

@luhenry luhenry force-pushed the fix-mono_ms_ticks branch 2 times, most recently from af9ab49 to ad46d09 Compare March 8, 2016 16:21
@luhenry
Copy link
Contributor Author

luhenry commented Mar 8, 2016

@alexrp I updated this PR to have mono_msec_boottime return a gint64, and modified Environment.TickCount icall accordingly

@alexrp
Copy link
Contributor

alexrp commented Mar 9, 2016

Looks OK to me. @kumpera: could you review also?


#ifdef HOST_WIN32
#include <windows.h>
#include <winbase.h>
Copy link
Member

Choose a reason for hiding this comment

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

winbase.h isn't meant to be included directly, windows.h above should be enough.

@luhenry
Copy link
Contributor Author

luhenry commented Mar 10, 2016

build

guint32
mono_msec_ticks (void)
/* we get "error: implicit declaration of function 'GetTickCount64'" */
ULONGLONG GetTickCount64(void);
Copy link
Member

Choose a reason for hiding this comment

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

You should wrap this into a #ifndef _MSC_VER to make sure we only get this on cygwin/mingw, otherwise we'll get errors on the VS build.

Because mono_msec_ticks would previously return the number of milliseconds since boot time, it would overflow after ~49 days. That would mean that anywhere you would use it, you would need to be careful of arithmetic overflow.

By simply returning a gint64 we will not overflow before ~30k years.

Fixes bug https://bugzilla.xamarin.com/show_bug.cgi?id=38666
@lewurm
Copy link
Contributor

lewurm commented Mar 29, 2016

@kumpera please review :)

@lewurm
Copy link
Contributor

lewurm commented Mar 29, 2016

LGTM. please fix the cygwin issue mentioned by @akoeplinger

@akoeplinger
Copy link
Member

@lewurm the issue was fixed, GitHub just doesn't collapse the commit because the line didn't change.

@akoeplinger
Copy link
Member

oh and please note that if you rebase the Windows build will be red anyway because we have a general issue there right now

@dnfclas
Copy link

dnfclas commented Apr 1, 2016

@ludovic-henry, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@luhenry
Copy link
Contributor Author

luhenry commented Apr 6, 2016

@kumpera could you please review?

@lewurm
Copy link
Contributor

lewurm commented Apr 6, 2016

build

@luhenry luhenry merged commit 6b139f4 into mono:master Apr 25, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
[runtime] Fix potential overflow when using mono_msec_ticks

Commit migrated from mono/mono@6b139f4
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 this pull request may close these issues.

None yet

5 participants