From 2660e9a4822790d04b1899c0d6ff37d99b36b8c1 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Tue, 14 Aug 2018 13:10:10 -0300 Subject: [PATCH] ras-report: avoid copying after addr.sun_path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit As warned by gcc: ras-report.c: In function ‘setup_report_socket’: ras-report.c:36:2: warning: ‘strncpy’ output truncated before terminating nul copying 25 bytes from a string of the same length [-Wstringop-truncation] strncpy(addr.sun_path, ABRT_SOCKET, strlen(ABRT_SOCKET)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The strncpy logic there is wrong. Fix it and be sure to have a NUL terminated string filled at addr.sun_path. Signed-off-by: Mauro Carvalho Chehab --- ras-report.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ras-report.c b/ras-report.c index d4beee0..cb0a9e8 100644 --- a/ras-report.c +++ b/ras-report.c @@ -33,7 +33,8 @@ static int setup_report_socket(void){ memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, ABRT_SOCKET, strlen(ABRT_SOCKET)); + strncpy(addr.sun_path, ABRT_SOCKET, sizeof(addr.sun_path)); + addr.sun_path[sizeof(addr.sun_path) - 1] = '\0'; rc = connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)); if (rc < 0){ -- 2.50.1