poggit / libasynql

Asynchronous MySQL access library for PocketMine plugins.
https://poggit.github.io/libasynql
Apache License 2.0
132 stars 44 forks source link

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

Open Swift-Strider opened 2 years ago

Swift-Strider commented 2 years ago

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"

SOF3 commented 2 years ago

Why would you create single character files to start with?

Swift-Strider commented 2 years ago

Why would you create single character files to start with?

I know, it's pretty strange to have your file named like that. But to me, this issue is still valid.

ghost commented 2 years ago

Why would you create single character files to start with?

because less characters = more performance kekw

SOF3 commented 2 years ago

Why would you create single character files to start with?

because less characters = more performance kekw

Definitely. We need a plugin that bans players with more than 5 characters in their name.