src/test: s/strcpy/strncpy

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>
This commit is contained in:
songweibin 2019-07-25 15:21:43 +08:00
parent 65c259c7b7
commit 0c706687e5
2 changed files with 4 additions and 2 deletions

View 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;

View 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;