brutella / hkknx-public

hkknx is a HomeKit KNX bridge for KNX.
https://hochgatterer.me/hkknx
99 stars 6 forks source link

empty Fan object results in panic/crash #145

Closed gregrahn closed 2 years ago

gregrahn commented 2 years ago

An empty Fan object was created which then crashed the hkknx process. Upon restart, the configuration is loaded but causes an immediate crash of hkknx. Process is unable to be restarted successfully until invalid accessory is removed from database/server.json. Stack trace below.

Version 2.0.1

Steps to reproduce:

Seems likely that the non-optional attribute rotation-speed is missing a validation check before the object is created.

~/database $ cat server.json.ok | jq '.' > a
~/database $ cat server.json.crash | jq '.' > b
~/database $ diff a b
56468a56469,56502
>     },
>     {
>       "id": "840e72ee-0316-4ae7-adff-71b7e8d72637",
>       "pid": "1660eedd-2f09-42a8-b2d7-7505d29c1bb4",
>       "name": "Fan",
>       "manufacturer": "",
>       "model": "",
>       "room": "",
>       "archived": false,
>       "disabled": false,
>       "created_at": "2021-11-02T14:44:34.885496775+02:00",
>       "service": {
>         "type": "fan",
>         "properties": [
>           {
>             "type": "rotation-speed",
>             "dpst": "DPST-5-1",
>             "listen": "",
>             "write": "",
>             "init": "",
>             "optional": false,
>             "enabled": false
>           },
>           {
>             "type": "block",
>             "dpst": "DPT-1",
>             "listen": "",
>             "write": "",
>             "init": "",
>             "optional": true,
>             "enabled": false
>           }
>         ]
>       }
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x623c6c]

goroutine 98 [running]:
github.com/brutella/hkknx/app.(*Fan).bind(0x1711c60, 0x1711c40, 0xaf969c, 0x1480558)
    /Users/mah/Source/Code/Go/src/github.com/brutella/hkknx/app/fan.go:23 +0x78
github.com/brutella/hkknx/app.(*app).accessoriesInProject(0x1146500, 0x111dc80, 0xaf969c, 0x1480558, 0xea5de0, 0x1, 0x0, 0x0)
    /Users/mah/Source/Code/Go/src/github.com/brutella/hkknx/app/app.go:952 +0x364
github.com/brutella/hkknx/app.(*app).Run.func2(0xaf582c, 0x100a8a0, 0x111dc80, 0x1146500, 0x1480558, 0x1026d70)
    /Users/mah/Source/Code/Go/src/github.com/brutella/hkknx/app/app.go:353 +0x144
created by github.com/brutella/hkknx/app.(*app).Run
    /Users/mah/Source/Code/Go/src/github.com/brutella/hkknx/app/app.go:344 +0x434
brutella commented 2 years ago

Thanks for your detailed description.

I've just uploaded a new pre-release build of version 2.0.1, which includes a bug fix. You can install the latest build version from the web UI by clicking on the version number in the footer and selecting "Install Latest Version".