From 3d74bd6acf6cab2e25e4f15ce6bc3c334df79a78 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 30 Oct 2023 12:26:28 +0100 Subject: [PATCH] feat: update system-time rule to not trigger on `time.Now().Round(0).UTC()` --- src/system-time.ql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/system-time.ql b/src/system-time.ql index 86c23a0..f25b95d 100644 --- a/src/system-time.ql +++ b/src/system-time.ql @@ -16,6 +16,8 @@ predicate isIrrelevantPackage(string packageName) { from CallExpr call where call.getTarget().getQualifiedName() = "time.Now" and + not call.getParent().(CallExpr).getTarget().getQualifiedName() = "Round" and + not call.getParent*().(CallExpr).getTarget().getQualifiedName() = "UTC" and // string formatting is usually a false positive (used in logging etc.), // so it's usually ok to ignore. // but there could be false negatives (if the string formatting output is written to a consensus state) @@ -46,4 +48,5 @@ where | c.getAComment().getText().matches("%SAFE:%") ) -select call, "Calling the system time may be a possible source of non-determinism" +select call, + "Calling the system time may be a possible source of non-determinism. Use time.Now().Round(0).UTC() instead."