From 480aefd0d78843ba004cc32e57c1d0a45a40fd9e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Tue, 13 Aug 2024 09:27:59 +0200 Subject: [PATCH] Assert "length > 0" for Meter.getUiName functions Because xSnprintf() will crash if the buffer size specified is zero. --- CPUMeter.c | 2 ++ DynamicMeter.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/CPUMeter.c b/CPUMeter.c index f5716d93e..1451ed77a 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -55,6 +55,8 @@ static void CPUMeter_init(Meter* this) { // Custom uiName runtime logic to include the param (processor) static void CPUMeter_getUiName(const Meter* this, char* buffer, size_t length) { + assert(length > 0); + if (this->param > 0) xSnprintf(buffer, length, "%s %u", Meter_uiName(this), this->param); else diff --git a/DynamicMeter.c b/DynamicMeter.c index 513296023..605474f83 100644 --- a/DynamicMeter.c +++ b/DynamicMeter.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "DynamicMeter.h" +#include #include #include #include @@ -97,6 +98,8 @@ static const char* DynamicMeter_getCaption(const Meter* this) { } static void DynamicMeter_getUiName(const Meter* this, char* name, size_t length) { + assert(length > 0); + const Settings* settings = this->host->settings; const DynamicMeter* meter = Hashtable_get(settings->dynamicMeters, this->param); if (meter) {