Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext-mongodb crashes if empty collection name #345

Open
xwz opened this issue Nov 20, 2021 · 1 comment
Open

ext-mongodb crashes if empty collection name #345

xwz opened this issue Nov 20, 2021 · 1 comment
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug

Comments

@xwz
Copy link

xwz commented Nov 20, 2021

What steps will reproduce the problem?

<?php
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');

use yii\mongodb\Connection;

$connection = new Connection(['dsn' => 'mongodb://localhost:27017/test']);
var_dump($connection->getCollection('')->findOne());

What's expected?

Throw an exception

What do you get instead?

PHP crashes

mongo-c-driver/work/mongo-c-driver-1.17.1/src/libmongoc/src/mongoc/mongoc-cursor.c:1118
_mongoc_cursor_collection(): precondition failed: *collection_len > 0

Possible fix: in yii2-mongodb/src/Database.php

public function getCollection($name, $refresh = false)
{
    if (empty($name)) {
        throw new InvalidParamException('A non-empty collection "$name" is required');
    }
    ...
}
@bizley bizley added the status:to be verified Needs to be reproduced and validated. label Nov 20, 2021
@samdark samdark added status:ready for adoption Feel free to implement this issue. type:bug Bug and removed status:to be verified Needs to be reproduced and validated. labels Nov 21, 2021
@samdark
Copy link
Member

samdark commented Nov 21, 2021

That's a bit werid behavior for a mongodb driver. A check for empty collection won't hurt anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants