]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test_filejournal.cc: use strncpy and terminate with '\0'
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 13 Mar 2014 16:21:53 +0000 (17:21 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Thu, 13 Mar 2014 16:21:53 +0000 (17:21 +0100)
CID 966632 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW)
 2. fixed_size_dest: You might overrun the 200 byte fixed-size string
 "path" by copying "args[0UL]" without checking the length.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/test/test_filejournal.cc

index 3691fa64f4bec2df087e5a426017cf896b6517d5..e50e5dce0cb9b1d39836f1454ab5dab93a815b0b 100644 (file)
@@ -72,7 +72,9 @@ int main(int argc, char **argv) {
   finisher = new Finisher(g_ceph_context);
   
   if (!args.empty()) {
-    strcpy(path, args[0]);
+    size_t copy_len = std::min(sizeof(path)-1, strlen(args[0]));
+    strncpy(path, args[0], copy_len);
+    path[copy_len] = '\0';
   } else {
     srand(getpid()+time(0));
     snprintf(path, sizeof(path), "/tmp/ceph_test_filejournal.tmp.%d", rand());