]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
src/test: s/strcpy/strncpy
authorsongweibin <song.weibin@zte.com.cn>
Thu, 25 Jul 2019 07:21:43 +0000 (15:21 +0800)
committersongweibin <song.weibin@zte.com.cn>
Thu, 25 Jul 2019 07:21:43 +0000 (15:21 +0800)
fix klocwork issues:
function 'strcpy' does not check buffer boundaries but outputs to buffer 'watcher.addr' of fixed size (256)

Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/test/librados_test_stub/TestWatchNotify.cc
src/test/librbd/managed_lock/test_mock_BreakRequest.cc

index 0068d075e6016fa76704e544323ca2ffb5ded0c9..71b1c8d428002370cf401a08014c2178fb7bedee 100644 (file)
@@ -77,7 +77,8 @@ int TestWatchNotify::list_watchers(int64_t pool_id, const std::string& nspace,
          watcher->watch_handles.begin();
        it != watcher->watch_handles.end(); ++it) {
     obj_watch_t obj;
-    strcpy(obj.addr, it->second.addr.c_str());
+    strncpy(obj.addr, it->second.addr.c_str(), sizeof(obj.addr) - 1);
+    obj.addr[sizeof(obj.addr) - 1] = '\0';
     obj.watcher_id = static_cast<int64_t>(it->second.gid);
     obj.cookie = it->second.handle;
     obj.timeout_seconds = 30;
index efab85e94446159762ccef44e23ab451bb4163c7..d47799c6d7685d310524700bc1a045f16dd5f4be 100644 (file)
@@ -81,7 +81,8 @@ public:
       expect.WillOnce(Return(r));
     } else {
       obj_watch_t watcher;
-      strcpy(watcher.addr, (address + ":0/0").c_str());
+      strncpy(watcher.addr, (address + ":0/0").c_str(), sizeof(watcher.addr) - 1);
+      watcher.addr[sizeof(watcher.addr) - 1] = '\0';
       watcher.watcher_id = 0;
       watcher.cookie = watch_handle;