Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

PHP: count gmdate, strtotime, mktime and getdate as clock reads (#1419)

Hashem Alkhanaiziebf614bb3cc3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2421490f..ff9177a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+- PHP: `gmdate()`, `idate()`, `getdate()`, `localtime()`, `mktime()`, `gmmktime()`, `strtotime()`
+ and `gettimeofday()` count as reading the clock, as `date()` and `time()` do. Before, a function
+ that called them was bridged as pure, and `analyze` left them out of "Clock and random numbers"
+ (#1407).
- CONTRIBUTING's "Set up" table has a Kotlin row (`kotlinc` and a JDK 17+), and its C row says
the C tests also need Python 3.9+, which calls the library through ctypes. A test checks that
the table has a row for every language (#1352, #1395 by @iyazici00).
diff --git a/src/lang/effects.rs b/src/lang/effects.rs
index 2037f19a..35a912ed 100644
--- a/src/lang/effects.rs
+++ b/src/lang/effects.rs
@@ -294,6 +294,16 @@ fn clock_and_random(lang: Lang) -> &'static [&'static str] {
"array_rand(",
"random_bytes(",
"lcg_value(",
+ // A match starts at a name boundary, so `date(` and `time(` miss these. Each reads
+ // now when given no timestamp or a relative string.
+ "gmdate(",
+ "idate(",
+ "getdate(",
+ "localtime(",
+ "mktime(",
+ "gmmktime(",
+ "strtotime(",
+ "gettimeofday(",
],
Lang::Csharp => &[
"DateTime.Now",
@@ -1805,6 +1815,18 @@ mod tests {
"<?php\nfunction f() { return date('Y'); }\n",
Risk::ClockAndRandom,
),
+ (
+ Lang::Php,
+ "x.php",
+ "<?php\nfunction f() { return gmdate('Y'); }\n",
+ Risk::ClockAndRandom,
+ ),
+ (
+ Lang::Php,
+ "x.php",
+ "<?php\nfunction f() { return strtotime('tomorrow'); }\n",
+ Risk::ClockAndRandom,
+ ),
(
Lang::Php,
"deck.php",