Page 1 of 1

[Bug] Long log group names cause system crash

Posted: Wed Jun 08, 2016 8:59 am
by 3zuli
Yesterday I was playing around with some new log groups in the firmware. I had a variable, which I wanted to log, so I created a log group and added the variable to it. It compiled without errors. I was able to flash the Crazyflie, after that it rebooted as usual and waited for connection. Then, as soon as I start my program to connect to it, the CF just reboots. Afterwards the red LED is flashing in bursts of (I believe) 3 short flashes, but the Rx/Tx LED doesn't go off, signalizing that the radio communication wasn't dropped. The CF can still be manually rebooted and re-flashed after this.
Here's the bit of code I used to diagnose the problem (please excuse the placeholder-like names :) ):

Code: Select all

static uint16_t sampleText = 12; // Placeholder variable for testing
...
LOG_GROUP_START(cmdLoremIpsum)
LOG_ADD(LOG_UINT16, lipsumAveryL, &sampleText) // Will work without problems
//LOG_ADD(LOG_UINT16, lipsumAveryLongItemName, &sampleText) // Will cause system reset
LOG_GROUP_STOP(cmdLoremIpsum)
By changing the length of the log group name and this item name, I found that the maximum combined length of the group and item name is 25 characters, above that the system crashes. I don't know if the name length limit is intended, or is a bug. In the first case, it would be good to add this note to the Logging tutorial/documentation. In the latter case, this should throw an error or a warning during compilation.
For these tests I used my own fork of crazyflie-firmware, which hasn't been kept up-to-date with the official github repo since about Dec 2015. I wasn't able to test this yet with the latest firmware version, therefore I didn't submit it as an Issue on github. Can someone test this with the official latest firmware?

Re: [Bug] Long log group names cause system crash

Posted: Wed Jun 08, 2016 10:11 am
by Che.
Thanks for sharing this info!
Greets, Che

Re: [Bug] Long log group names cause system crash

Posted: Thu Jun 09, 2016 8:23 am
by kristoffer
I ran into the same problem some weeks ago and spent some time on understanding what was going on :-)
I added an assert to param.c to catch this problem and fail fast (in commit 8668a3bad34d62bae3f275e1719deb60099fe433).

If you are on an old code base you probably just get unexpected behaviour as you would write outside the buffer and corrupt the memory. If you are on a newer code base, where the assert exists, you should get a log message in the console telling you about the assert failure in param.c. Hopefully that would lead you to the comment in param.c saying

// Too long! The name of the group or the parameter may be too long.

I agree that it might be a good idea to clarify this in the documentation as well. It would be fantastic if you would like to help out and contribute this on the wiki. I will be more than happy to help you out on the way. Thanks!

- Kristoffer