codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.55k stars 343 forks source link

Immudb crash when callins SQLExec with `nil` parameter #1508

Closed SimoneLazzaris closed 1 year ago

SimoneLazzaris commented 1 year ago

What happened

Immudb server crashed when executing an (invalid) SQLExec query

What you expected to happen

Invalid or inconsistent queries should rejected in the client SDK, and definitively shouldn't crash the server

How to reproduce it (as minimally and precisely as possible) Create this table on immudb, defaultdb database:

CREATE TABLE IF NOT EXISTS t (id VARCHAR[256], value INTEGER, PRIMARY KEY id)

Then execute this go code:

package main

import (
    "context"
    immuclient "github.com/codenotary/immudb/pkg/client"
    "log"
)

func main() {
    opts := immuclient.DefaultOptions().WithAddress("127.0.0.1").WithPort(3322)
    client := immuclient.NewClient().WithOptions(opts)
    ctx := context.Background()
    err := client.OpenSession(ctx, []byte("immudb"), []byte("immudb"), "defaultdb")
    if err != nil {
        log.Fatalln("Failed to connect. Reason:", err)
    }
    _, err = client.SQLExec(ctx, "update t set value=@val where id=@id", nil)
    if err != nil {
        log.Fatalln("Error", err)
    }
}

Environment

# run "immu* version" and copy/paste the output here
$ ./immudb-v1.4.1-linux-amd64-static version
immudb 1.4.1
Commit  : 99e4f1ea5970177be5287da2529849cd5ee64696
Built at: Mon, 21 Nov 2022 14:50:26 CET
Static  : true
jeroiraz commented 1 year ago

With current master I'm not able to reproduce it.

Expected error is returned instead "table does not exist (t)", error detected when parsing the sql statement

jeroiraz commented 1 year ago

Actually, I'm not able to reproduce it either with v1.4.1

commit 99e4f1ea5970177be5287da2529849cd5ee64696 (HEAD, tag: v1.4.1, origin/release/v1.4.1)

SimoneLazzaris commented 1 year ago

Tried again, it is not triggering if table t is missing or empty.

After inserting a couple of rows, it will trigger:

immuclient>exec CREATE TABLE IF NOT EXISTS t (id VARCHAR[256], value INTEGER, PRIMARY KEY id)
Updated rows: 0 
immuclient>exec insert into t(id,value) values('aa',12);
Updated rows: 1 
immuclient>exec insert into t(id,value) values('ab',13);
Updated rows: 1 

and then go run

SimoneLazzaris commented 1 year ago

https://user-images.githubusercontent.com/11316967/218041806-7cd96220-fb96-4106-a00e-7a561dd6edcc.mp4