File: bug72963.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (92 lines) | stat: -rw-r--r-- 1,710 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--TEST--
Bug #72963 (Null-byte injection in CreateFromFormat and related functions)
--INI--
date.timezone=UTC
--FILE--
<?php
$strings = [
	'8/8/2016',
	"8/8/2016\0asf",
];

foreach ($strings as $string) {
	$d1 = $d2 = $d3 = NULL;
	echo "\nCovering string: ", addslashes($string), "\n\n";

	try {
		$d1 = DateTime::createFromFormat('!m/d/Y', $string);
	} catch (ValueError $v) {
		echo $v->getMessage(), "\n";
	}

	try {
		$d2 = DateTimeImmutable::createFromFormat('!m/d/Y', $string);
	} catch (ValueError $v) {
		echo $v->getMessage(), "\n";
	}

	try {
		$d3 = date_parse_from_format('m/d/Y', $string);
	} catch (ValueError $v) {
		echo $v->getMessage(), "\n";
	}

	var_dump($d1, $d2, $d3);
}
?>
--EXPECT--
Covering string: 8/8/2016

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2016-08-08 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}
object(DateTimeImmutable)#2 (3) {
  ["date"]=>
  string(26) "2016-08-08 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}
array(12) {
  ["year"]=>
  int(2016)
  ["month"]=>
  int(8)
  ["day"]=>
  int(8)
  ["hour"]=>
  bool(false)
  ["minute"]=>
  bool(false)
  ["second"]=>
  bool(false)
  ["fraction"]=>
  bool(false)
  ["warning_count"]=>
  int(0)
  ["warnings"]=>
  array(0) {
  }
  ["error_count"]=>
  int(0)
  ["errors"]=>
  array(0) {
  }
  ["is_localtime"]=>
  bool(false)
}

Covering string: 8/8/2016\0asf

DateTime::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
DateTimeImmutable::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
date_parse_from_format(): Argument #2 ($datetime) must not contain any null bytes
NULL
NULL
NULL