cr-service: fix gcc-8 error

Submitted by Adrian Reber on Aug. 2, 2018, 10:30 a.m.

Details

Message ID 20180802103034.10693-1-adrian@lisas.de
State Accepted
Series "cr-service: fix gcc-8 error"
Headers show

Commit Message

Adrian Reber Aug. 2, 2018, 10:30 a.m.
From: Adrian Reber <areber@redhat.com>

The latest patches to cr-service.c broke compilation with gcc-8:

criu/cr-service.c: In function ‘setup_opts_from_req’:
criu/cr-service.c:323:3: error: ‘strncpy’ specified bound 4096 equals destination size [-Werror=stringop-truncation]
   strncpy(images_dir_path, opts.imgs_dir, PATH_MAX);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu/cr-service.c:343:3: error: ‘strncpy’ specified bound 4096 equals destination size [-Werror=stringop-truncation]
   strncpy(work_dir_path, opts.work_dir, PATH_MAX);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

This fixes the errors by specifying the strncpy() size as 'PATH_MAX - 1'.

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 criu/cr-service.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-service.c b/criu/cr-service.c
index dc2ff05f7..643aba9cf 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -320,7 +320,7 @@  static int setup_opts_from_req(int sk, CriuOpts *req)
 	 *  * apply_config(rpc_conf)
 	 */
 	if (opts.imgs_dir && imgs_changed_by_rpc_conf)
-		strncpy(images_dir_path, opts.imgs_dir, PATH_MAX);
+		strncpy(images_dir_path, opts.imgs_dir, PATH_MAX - 1);
 	else
 		sprintf(images_dir_path, "/proc/%d/fd/%d", ids.pid, req->images_dir_fd);
 
@@ -340,7 +340,7 @@  static int setup_opts_from_req(int sk, CriuOpts *req)
 
 	/* chdir to work dir */
 	if (opts.work_dir && work_changed_by_rpc_conf)
-		strncpy(work_dir_path, opts.work_dir, PATH_MAX);
+		strncpy(work_dir_path, opts.work_dir, PATH_MAX - 1);
 	else if (req->has_work_dir_fd)
 		sprintf(work_dir_path, "/proc/%d/fd/%d", ids.pid, req->work_dir_fd);
 	else