will-moss / isaiah

Self-hostable clone of lazydocker for the web. Manage your Docker fleet with ease
MIT License
971 stars 19 forks source link

Panic when attempting to view container env with a null variable #18

Open pR0Ps opened 1 week ago

pR0Ps commented 1 week ago

Traceback:

panic: runtime error: index out of range [1] with length 1

goroutine 357 [running]:
will-moss/isaiah/server/resources.Container.GetEnv({{0xc00011a180, 0x40}, {0xc00019ed35, 0x7}, 0x0, {0xc00019ec98, 0x8}, {0xc000304060, 0x22}, {0xc000118aa0, ...}, ...}, ...)
     isaiah/app/server/resources/containers.go:694 +0x3a7
will-moss/isaiah/server/server.Containers.RunCommand({}, 0xc00009e870, {0xa66b10?, 0xc000024cc0}, {{0xc0000291d0, 0x15}, 0xc00022c4e0, {0x0, 0x0}, {0x0, ...}, ...})
     isaiah/app/server/server/containers.go:633 +0x3645
will-moss/isaiah/server/server.(*Server).Handle(0xc00009e870, {0xa66b10, 0xc000024cc0}, {0xc000409fb8, 0x1, 0xc0001b4f40?})
     isaiah/app/server/server/server.go:541 +0x8d0
created by main.main.func4 in goroutine 12
     isaiah/app/main.go:286 +0xcb

To reproduce, run the following with docker compose, go to port 3000, and attempt to view the container's environment:

version: "3.3"
services:
  isaiah:
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - 3000:3000
    image: mosswill/isaiah
    environment:
      TEST: null

docker inspect shows the environment as:

"Env": [
    "TEST",
    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
    "DOCKER_RUNNING=true"
],

Seems like because there's no = in the TEST variable, the following snippet is causing the failure: https://github.com/will-moss/isaiah/blob/50834d1c6e3deb3e945c835e8aee4b6b2e0be268/app/server/resources/containers.go#L692-L694

from strings.Split doc:

If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s.

So strings.Split(raw[i], "=") will return ["TEST"], which causes the panic when attempting to access it's 1th index.

will-moss commented 1 week ago

Hi,

Thank you very much for opening the issue, and most importantly for finding the exact root and solution.

I have just published a new release that fixes that case.

It should work better now!