Skip to content

Commit c788322

Browse files
authored
Merge pull request #42 from SimonFrings/path
Reject null byte in path to SQLite database file
2 parents ec494da + cf2ffd7 commit c788322

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

res/sqlite-worker.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
'id' => $data->id,
9191
'error' => array('message' => $e->getMessage())
9292
));
93+
} catch (Error $e) {
94+
$out->write(array(
95+
'id' => $data->id,
96+
'error' => array('message' => $e->getMessage())
97+
));
9398
}
9499
} elseif ($data->method === 'open' && \count($data->params) === 2 && \is_string($data->params[0]) && \is_int($data->params[1])) {
95100
// open database with two parameters: $filename, $flags
@@ -108,6 +113,11 @@
108113
'id' => $data->id,
109114
'error' => array('message' => $e->getMessage())
110115
));
116+
} catch (Error $e) {
117+
$out->write(array(
118+
'id' => $data->id,
119+
'error' => array('message' => $e->getMessage())
120+
));
111121
}
112122
} elseif ($data->method === 'exec' && $db !== null && \count($data->params) === 1 && \is_string($data->params[0])) {
113123
// execute statement and suppress PHP warnings

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 testOpenInvalidPathWithNullByteRejects($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('RuntimeException'))
155+
);
156+
157+
$loop->run();
158+
}
159+
137160
/**
138161
* @dataProvider provideSocketFlags
139162
* @param bool $flag

0 commit comments

Comments
 (0)