arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.97k stars 4.77k forks source link

ESP32 string length overflow bug in xdrv_12_home_assistant.ino #11347

Closed vic42 closed 3 years ago

vic42 commented 3 years ago

PROBLEM DESCRIPTION

A clear and concise description of what the problem is.

ESP32 string length overflow bug in xdrv_12_home_assistant.ino

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [ ] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
- [ ] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:

TO REPRODUCE

Steps to reproduce the behavior:

Here's the invalid JSON that tasmota was sending (extra comma after last null): 2021-03-13 11:10:21 WARNING (MainThread) [hatasmota.discovery] Invalid discovery message 3C6105**:

'{"ip":"192.168.1.220","dn":"Tasmota-Heltec","fn":["Tasmota1",null,null,null,null,null,null,null],"hn":"HeltecTopic-0724","mac":"3C6105******","md":"Heltec WiFi Kit 32","ty":0,"if":0,"ofln":"Offline","onln":"Online","state":["OFF","ON","TOGGLE","HOLD"],"sw":"9.3.1","t":"HeltecTopic","ft":"%prefix%/%topic%/","tp":["cmnd","stat","tele"],"rl":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"swc":[-1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],"swn":[null,"Switch2","Switch3","Switch4",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,],"btn":[0,0,0,0,0,0,0,0],"so":{"4":0,"11":0,"13":0,"17":0,"20":0,"30":0,"68":0,"73":0,"82":0,"114":1,"117":0},"lk":1,"lt_st":0,"sho":[0,0,0,0],"ver":1}'

Note the ostensibly stray comma before the bracket at the end of the "swn" value: null,null,],

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen.

A valid and complete JSON string

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

I am only reporting this as a proxy from Tasmota Discord chat. See thread here: https://discord.com/channels/479389167382691863/790185752855052288/820353710185906219 There is a good description of what is actually going wrong. I checked the code and found the cause of the problem. The issue was introduced when increasing the number of possible switches in tasmota32.

stemp4 is only TOPSZ (151 Bytes) long. The resulting JSON string in this code becomes longer than that on a regular basis and gets truncated: https://github.com/arendst/Tasmota/blob/development/tasmota/xdrv_12_home_assistant.ino#L302-L308

(Please, remember to close the issue when the problem has been addressed)

scottcopus commented 3 years ago

@vic42 Thanks for opening this bug. I finally had some time to submit this bug report when I saw you beat me to the punch. 👍

arendst commented 3 years ago

Thx for documented reporting.