ConSol-Monitoring / snclient

SNClient+ - Cross platform monitoring agent
MIT License
50 stars 8 forks source link

runtime error with space as parameter #88

Closed sgrallert closed 7 months ago

sgrallert commented 8 months ago

Hello everyone,

I'm currently running into a runtime error when i try to pass a space character via API. I need the space for backward compatibility reasons.

I have defined an external script command as follows:

[/settings/external scripts/scripts]
test = cmd /c echo '%ARG1%'

I execute an Api call as follows:

curl -k --header "password: xxx" "https://172.25.221.142:18443/query/test?%20"

I get the following error back in the console/log:

[2024-02-05 10:40:00.360][Trace][pid:4580][listener:379] incoming http(s) connection from 172.25.221.63:48090
[2024-02-05 10:40:00.360][Trace][pid:4580][listener:389] http request:
GET /query/test?%20 HTTP/1.1
Host: 172.25.221.142:18443
Accept: */*
Password: xxx
User-Agent: curl/7.58.0


[2024-02-05 10:40:00.367][Trace][pid:4580][snclient:706] command: test
[2024-02-05 10:40:00.382][Trace][pid:4580][snclient:707] args: []string{" "}
[2024-02-05 10:40:00.383][Debug][pid:4580][check_wrap:64] command before macros expanded: cmd /c echo '%ARG1%'
[2024-02-05 10:40:00.399][Error][pid:4580][snclient:679] ********* PANIC *********
Panic: runtime error: invalid memory address or nil pointer dereference
[2024-02-05 10:40:00.412][Error][pid:4580][snclient:681] **** Stack:
[2024-02-05 10:40:00.412][Error][pid:4580][snclient:682] goroutine 71 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.21.6/x64/src/runtime/debug/stack.go:24 +0x5e
pkg/snclient.(*Agent).logPanicRecover(0x0?)
        /home/runner/work/snclient/snclient/pkg/snclient/snclient.go:682 +0x168
panic({0xa55480?, 0x112c1f0?})
        /opt/hostedtoolcache/go/1.21.6/x64/src/runtime/panic.go:914 +0x21f
pkg/snclient.MakeCmd({0xc52140, 0xc00018cb60}, {0xc00012cba0, 0xf}, {0xc00012cc30, 0x9})
        /home/runner/work/snclient/snclient/pkg/snclient/snclient.go:1309 +0x209
pkg/snclient.(*Agent).runExternalCommandString(0xc0000a4370, {0xc52140, 0xc00018cb60}, {0xc00012cba0, 0xf}, 0x1?)
        /home/runner/work/snclient/snclient/pkg/snclient/snclient.go:1111 +0x19c
pkg/snclient.(*CheckWrap).Check(0xc0000a1040, {0xc52140, 0xc00018cb60}, 0xc0000a4370, 0xc00009cfc0, {0x1?, 0x1?, 0x10?})
        /home/runner/work/snclient/snclient/pkg/snclient/check_wrap.go:74 +0x6ee
pkg/snclient.(*Agent).runCheck(0xa47680?, {0xc52098, 0xc0005763f0}, {0xc00000e94b, 0x4}, {0xc000098290, 0x1, 0x1})
        /home/runner/work/snclient/snclient/pkg/snclient/snclient.go:743 +0x3f5
pkg/snclient.(*Agent).RunCheckWithContext(0xc00019b5e8?, {0xc52098?, 0xc0005763f0?}, {0xc00000e94b?, 0xc46bd8?}, {0xc000098290?, 0x0?, 0x3?})
        /home/runner/work/snclient/snclient/pkg/snclient/snclient.go:697 +0x2a
pkg/snclient.(*HandlerWebLegacy).ServeHTTP(0xc00009e1c8, {0xc50920, 0xc0000a1000}, 0xc0000dc100)
        /home/runner/work/snclient/snclient/pkg/snclient/listen_web.go:295 +0xc5
pkg/snclient.(*Listener).WrappedCheckHTTPHandler(0xc00000e944?, {0x216674c8798, 0xc000097980}, 0xc000072000, {0xc50920, 0xc0000a1000}, 0xc0000dc100)
        /home/runner/work/snclient/snclient/pkg/snclient/listener.go:441 +0x29c
pkg/snclient.(*Listener).startListenerHTTP.func2({0xc50920?, 0xc0000a1000?}, 0xc000098200?)
        /home/runner/work/snclient/snclient/pkg/snclient/listener.go:351 +0x3f
net/http.HandlerFunc.ServeHTTP(0xa50f80?, {0xc50920?, 0xc0000a1000?}, 0xc00000e944?)
        /opt/hostedtoolcache/go/1.21.6/x64/src/net/http/server.go:2136 +0x29
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0xc000202000, {0xc50920, 0xc0000a1000}, 0xc0000dc100)
        /home/runner/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.11/mux.go:443 +0x2b4
net/http.HandlerFunc.ServeHTTP(0xc00008c960?, {0xc50920?, 0xc0000a1000?}, 0xc000098110?)
        /opt/hostedtoolcache/go/1.21.6/x64/src/net/http/server.go:2136 +0x29
pkg/snclient.(*Listener).LogWrapHTTPHandler(0xc0000e0150, {0xc4c9e0, 0xc000204050}, {0xc51310?, 0xc0000100e0}, 0xc0000dc100)
        /home/runner/work/snclient/snclient/pkg/snclient/listener.go:397 +0x3d5
pkg/snclient.(*Listener).startListenerHTTP.func1.1({0xc51310?, 0xc0000100e0?}, 0x112d301?)
        /home/runner/work/snclient/snclient/pkg/snclient/listener.go:335 +0x3b
net/http.HandlerFunc.ServeHTTP(0xc520d0?, {0xc51310?, 0xc0000100e0?}, 0x112d3a0?)
        /opt/hostedtoolcache/go/1.21.6/x64/src/net/http/server.go:2136 +0x29
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0xc000202000, {0xc51310, 0xc0000100e0}, 0xc0000dc000)
        /home/runner/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.11/mux.go:90 +0x330
net/http.serverHandler.ServeHTTP({0xc000576330?}, {0xc51310?, 0xc0000100e0?}, 0x6?)
        /opt/hostedtoolcache/go/1.21.6/x64/src/net/http/server.go:2938 +0x8e
net/http.(*conn).serve(0xc0000d8000, {0xc52098, 0xc00003e750})
        /opt/hostedtoolcache/go/1.21.6/x64/src/net/http/server.go:2009 +0x5f4
created by net/http.(*Server).Serve in goroutine 50
        /opt/hostedtoolcache/go/1.21.6/x64/src/net/http/server.go:3086 +0x5cb
sni commented 7 months ago

thanks for reporting this. Actually two bugs here. The panic was because an error had not been handled and the single quotes haven't been parsed properly on windows either.