From 46692332db10ae06dbb1be20a390c260c00e1252 Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Thu, 2 Oct 2014 10:48:25 +0200 Subject: [PATCH] mount.ceph.c: ensure '\0' terminated string Reserve last char in array for '\0' to ensure termination of the string. Fix for: CID 1128383 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING) buffer_size_warning: Calling strncpy with a maximum size argument of 1000 bytes on destination array secret of size 1000 bytes might leave the destination string unterminated. Signed-off-by: Danny Al-Gaaf --- src/mount/mount.ceph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mount/mount.ceph.c b/src/mount/mount.ceph.c index 5c8bf959c37e8..8a0853fdf4596 100644 --- a/src/mount/mount.ceph.c +++ b/src/mount/mount.ceph.c @@ -175,11 +175,13 @@ static char *parse_options(const char *data, int *filesys_flags) } /* secret is only added to kernel options as - backwards compatilbity, if add_key doesn't + backwards compatibility, if add_key doesn't recognize our keytype; hence, it is skipped here and appended to options on add_key failure */ - strncpy(secret, value, sizeof(secret)); + size_t len = sizeof(secret); + strncpy(secret, value, len-1); + secret[len-1] = '\0'; saw_secret = secret; skip = 1; } else if (strncmp(data, "name", 4) == 0) { -- 2.39.5