Skip to content

Commit

Permalink
Merge pull request #42 from SimonFrings/path
Browse files Browse the repository at this point in the history
Reject null byte in path to SQLite database file
  • Loading branch information
clue authored Sep 24, 2021
2 parents ec494da + cf2ffd7 commit c788322
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions res/sqlite-worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
'id' => $data->id,
'error' => array('message' => $e->getMessage())
));
} catch (Error $e) {
$out->write(array(
'id' => $data->id,
'error' => array('message' => $e->getMessage())
));
}
} elseif ($data->method === 'open' && \count($data->params) === 2 && \is_string($data->params[0]) && \is_int($data->params[1])) {
// open database with two parameters: $filename, $flags
Expand All @@ -108,6 +113,11 @@
'id' => $data->id,
'error' => array('message' => $e->getMessage())
));
} catch (Error $e) {
$out->write(array(
'id' => $data->id,
'error' => array('message' => $e->getMessage())
));
}
} elseif ($data->method === 'exec' && $db !== null && \count($data->params) === 1 && \is_string($data->params[0])) {
// execute statement and suppress PHP warnings
Expand Down
23 changes: 23 additions & 0 deletions tests/FunctionalDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ public function testOpenInvalidPathRejects($flag)
$loop->run();
}

/**
* @dataProvider provideSocketFlags
* @param bool $flag
*/
public function testOpenInvalidPathWithNullByteRejects($flag)
{
$loop = \React\EventLoop\Factory::create();
$factory = new Factory($loop);

$ref = new \ReflectionProperty($factory, 'useSocket');
$ref->setAccessible(true);
$ref->setValue($factory, $flag);

$promise = $factory->open("test\0.db");

$promise->then(
null,
$this->expectCallableOnceWith($this->isInstanceOf('RuntimeException'))
);

$loop->run();
}

/**
* @dataProvider provideSocketFlags
* @param bool $flag
Expand Down

0 comments on commit c788322

Please sign in to comment.