From 19c0ce4c68fd424f48a71afbc9d8b7b67ba58709 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sun, 13 Mar 2022 14:45:03 +0100 Subject: [PATCH] macro: account for negative values in DECIMAL_STR_WIDTH() With negative numbers we wouldn't account for the minus sign, thus returning a string with one character too short, triggering buffer overflows in certain situations. (cherry picked from commit e3dd9ea8ea4510221f73071ad30ee657ca77565d) (cherry picked from commit 25b3c48ec5203a1220daaf33b8df6e50e79fd74a) Conflict:NA Reference:https://github.com/systemd/systemd-stable/commit/19c0ce4c68fd424f48a71afbc9d8b7b67ba58709 --- src/basic/macro.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/macro.h b/src/basic/macro.h index 072fed4378..5a3027ae5c 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -349,7 +349,7 @@ static inline int __coverity_check_and_return__(int condition) { #define DECIMAL_STR_WIDTH(x) \ ({ \ typeof(x) _x_ = (x); \ - unsigned ans = 1; \ + unsigned ans = 2; \ while ((_x_ /= 10) != 0) \ ans++; \ ans; \ -- 2.33.0