Skip to content

Sqlite crashes when strlen(file) === 1 #78

@Swift-Strider

Description

@Swift-Strider

Describe the bug
Only on Windows, the libasynql::create function crashes with the following config

type: "sqlite"
sqlite:
    file: "a" #NOTICE: `file` is a single character

with this error

ErrorException: "Uninitialized string offset 1" (EXCEPTION) in "C:/<pocketmine-dir>/virions/libasynql_dev-174.phar/src/poggit/libasynql/libasynql" at line 162

libasynql.php The comment marks the ErrorException.

private static function resolvePath(string $folder, string $path) : string{
    if($path[0] === "/"){
        return $path;
    }
    if(Utils::getOS() === "win"){
        if($path[0] === "\\" || $path[1] === ":"){
            // ErrorException thrown Above! ^^^^^^^ 
            return $path;
        }
    }
    return $folder . $path;
}

Another Bug
Furthermore, having file: "" throws an error on all platforms, but that config is invalid anyways. It's arguable if that should be fixed too.

Expected behavior
This should not crash.

Environment
OS: "win"
PocketMine version: "4.2.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions