From 4abf3e1264bdc0c89fed172b8657dc886e41552c Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 14 Aug 2025 12:08:27 -0700 Subject: [PATCH] Fix buffer-overflow in sha256 string construction Need to leave room for the last null-byte. --- src/tools/sha256file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/sha256file.cpp b/src/tools/sha256file.cpp index 2878db8e..47ad7979 100644 --- a/src/tools/sha256file.cpp +++ b/src/tools/sha256file.cpp @@ -103,7 +103,7 @@ string sha256sum(const char *fn) { } } SHA256_Final(sha, &ctx); - char res[SHA256_DIGEST_LENGTH * 2]; + char res[SHA256_DIGEST_LENGTH * 2 + 1]; for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) sprintf(res + (i * 2), "%02x", sha[i]); return "sha256:" + std::string(res, SHA256_DIGEST_LENGTH * 2);