]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mount.ceph.c: ensure '\0' terminated string
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 2 Oct 2014 08:48:25 +0000 (10:48 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Wed, 8 Oct 2014 20:56:22 +0000 (22:56 +0200)
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 <danny.al-gaaf@bisect.de>
src/mount/mount.ceph.c

index 5c8bf959c37e8afed9477b9b6e7b19d7813b3ba9..8a0853fdf4596e29a05db17cbdc2e5fee8e4cb98 100644 (file)
@@ -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) {