Skip to content

Commit 6e5e82b

Browse files
committed
Reject null byte in path to SQLite database file
1 parent ec494da commit 6e5e82b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Factory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ public function __construct(LoopInterface $loop = null)
104104
public function open($filename, $flags = null)
105105
{
106106
$filename = $this->resolve($filename);
107+
108+
if (\strpos($filename, "\0") !== false) {
109+
return \React\Promise\reject(new \InvalidArgumentException(
110+
'Invalid argument (filename) given: Invalid null byte in your SQLite database file path'
111+
));
112+
}
113+
107114
return $this->useSocket ? $this->openSocketIo($filename, $flags) : $this->openProcessIo($filename, $flags);
108115
}
109116

tests/FunctionalDatabaseTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,29 @@ public function testOpenInvalidPathRejects($flag)
134134
$loop->run();
135135
}
136136

137+
/**
138+
* @dataProvider provideSocketFlags
139+
* @param bool $flag
140+
*/
141+
public function testOpenInvalidPathWithNullByteReadAsOneByteWillReject($flag)
142+
{
143+
$loop = \React\EventLoop\Factory::create();
144+
$factory = new Factory($loop);
145+
146+
$ref = new \ReflectionProperty($factory, 'useSocket');
147+
$ref->setAccessible(true);
148+
$ref->setValue($factory, $flag);
149+
150+
$promise = $factory->open("test\0.db");
151+
152+
$promise->then(
153+
null,
154+
$this->expectCallableOnceWith($this->isInstanceOf('InvalidArgumentException'))
155+
);
156+
157+
$loop->run();
158+
}
159+
137160
/**
138161
* @dataProvider provideSocketFlags
139162
* @param bool $flag

0 commit comments

Comments
 (0)