File avoid_writing_at_end_of_buffer.patch of Package rasdaemon.10651

From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Subject: mce-amd-k8: be sure to not go past error_msg buffer
References: bsc#1128122
Patch-Mainline: v0.6.2
Git-commit: 54a74d94ac0c296c24e66efbee916afab1e3045f
Git-repo: git://git.infradead.org/users/mchehab/rasdaemon.git

As warned by gcc:

mce-amd-k8.c: In function ‘decode_k8_generic_errcode’:
mce-amd-k8.c:136:30: warning: ‘) ’ directive output may be truncated writing 2 bytes into a region of size between 0 and 4095 [-Wformat-truncation=]
   mce_snprintf(e->error_msg, "(%s) ", tmp_buf);
                              ^~~~~~~
ras-mce-handler.h:104:29: note: in definition of macro ‘mce_snprintf’
  snprintf(buf + __n, __len, fmt,  ##arg);  \
                             ^~~
ras-mce-handler.h:104:2: note: ‘snprintf’ output between 4 and 4099 bytes into a destination of size 4096
  snprintf(buf + __n, __len, fmt,  ##arg);  \
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mce-amd-k8.c:136:3: note: in expansion of macro ‘mce_snprintf’
   mce_snprintf(e->error_msg, "(%s) ", tmp_buf);
   ^~~~~~~~~~~~

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

Signed-off-by: Thomas Renninger <trenn@suse.com>

diff --git a/mce-amd-k8.c b/mce-amd-k8.c
index c8aa44c..dc772c2 100644
--- a/mce-amd-k8.c
+++ b/mce-amd-k8.c
@@ -125,7 +125,7 @@ static const char *highbits[32] = {
 
 static void decode_k8_generic_errcode(struct mce_event *e)
 {
-	char tmp_buf[4096];
+	char tmp_buf[4092];
 	unsigned short errcode = e->status & 0xffff;
 	int n;
 
openSUSE Build Service is sponsored by