From 4c6878014358ce087a527ed9067266c0b3be0eda Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 23 Feb 2024 13:04:08 +0000 Subject: [PATCH] format: sanitize username for null ref #64 --- src/renderer/widgets/IWidget.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index 5aa21e1..053d021 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -48,8 +48,13 @@ static std::string getTime() { IWidget::SFormatResult IWidget::formatString(std::string in) { + char* username = getlogin(); + + if (!username) + Debug::log(ERR, "Error in formatString, username null. Errno: ", errno); + IWidget::SFormatResult result; - replaceAll(in, "$USER", std::string{getlogin()}); + replaceAll(in, "$USER", std::string{username ? username : ""}); replaceAll(in, "
", std::string{"\n"}); if (in.contains("$TIME")) {