Dangerous edge case for non-null-terminated string

strncpy() does not place a null terminator when the max characters is reached of '9' in this case. So, any buttons with 9 or more in the source will wind up with a potentially non-null-terminated _label.
This commit is contained in:
Robert Wolff 2021-05-03 22:31:05 -07:00
parent 01b99a50d9
commit 092e58cff1
1 changed files with 1 additions and 0 deletions

View File

@ -36,6 +36,7 @@ void TFT_eSPI_Button::initButtonUL(
_textsize = textsize; _textsize = textsize;
_gfx = gfx; _gfx = gfx;
strncpy(_label, label, 9); strncpy(_label, label, 9);
_label[9] = 0; // strncpy does not place a null at the end. When 'label' is 9 characters, _label is not terminated.
} }
// Adjust text datum and x, y deltas // Adjust text datum and x, y deltas