BSlider: Copy the UpdateText inside UpdateTextChanged.
We can't rely on it not changing between calls, especially as
MaxUpdateTextWidth() changes the value and re-gets it, and
that's called at the end of this method always. So we need to
keep our own copy rather than using the one that's owned by
the subclass.
Fixes a use-after-free uncovered by the guarded heap in VolumeSlider,
reported in #19493.
Diff
headers/os/interface/Slider.h | 2 +-
src/kits/interface/Slider.cpp | 5 +++++
2 files changed, 5 insertions(+), 2 deletions(-)
@@ -201,7 +201,7 @@
char* fMinLimitLabel;
char* fMaxLimitLabel;
const char* fUpdateText;
char* fUpdateText;
int32 fMinValue;
int32 fMaxValue;
@@ -208,6 +208,7 @@
#endif
delete fModificationMessage;
free(fUpdateText);
free(fMinLimitLabel);
free(fMaxLimitLabel);
}
@@ -1054,7 +1055,9 @@
oldWidth = StringWidth(fUpdateText);
const char* oldUpdateText = fUpdateText;
fUpdateText = UpdateText();
free(fUpdateText);
fUpdateText = strdup(UpdateText());
bool updateTextOnOff = (fUpdateText == NULL && oldUpdateText != NULL)
|| (fUpdateText != NULL && oldUpdateText == NULL);