提交 7f1341d4 编写于 作者: Y ysuenaga

8216486: Possibility of integer overflow in JfrThreadSampler::run()

Reviewed-by: rehn, sgehwolf
上级 8af32fc3
/* /*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -499,8 +499,17 @@ void JfrThreadSampler::run() { ...@@ -499,8 +499,17 @@ void JfrThreadSampler::run() {
jlong now_ms = get_monotonic_ms(); jlong now_ms = get_monotonic_ms();
jlong next_j = java_interval + last_java_ms - now_ms; /*
jlong next_n = native_interval + last_native_ms - now_ms; * Let I be java_interval or native_interval.
* Let L be last_java_ms or last_native_ms.
* Let N be now_ms.
*
* Interval, I, might be max_jlong so the addition
* could potentially overflow without parenthesis (UB). Also note that
* L - N < 0. Avoid UB, by adding parenthesis.
*/
jlong next_j = java_interval + (last_java_ms - now_ms);
jlong next_n = native_interval + (last_native_ms - now_ms);
jlong sleep_to_next = MIN2<jlong>(next_j, next_n); jlong sleep_to_next = MIN2<jlong>(next_j, next_n);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册