Repository: mesos
Updated Branches:
  refs/heads/master 34e9e09b8 -> 4df496aaf


Replaced usage of `strcpy` in stout.

Various simple-minded static analysis tools warn against using `strcpy`
when the `src` buffer is not a C string literal. Although the way in
which stout was using `strcpy` should have been safe, `memcpy` is a more
direct way to express what we want to do anyway.

Review: https://reviews.apache.org/r/52085/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f86ff5c7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f86ff5c7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f86ff5c7

Branch: refs/heads/master
Commit: f86ff5c71289d2338b58742963fcc7170efb1382
Parents: 34e9e09
Author: Neil Conway <neil.con...@gmail.com>
Authored: Thu Sep 22 16:31:31 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Thu Sep 22 16:31:31 2016 +0200

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/mktemp.hpp        | 3 ++-
 3rdparty/stout/include/stout/os/posix/mkdtemp.hpp | 4 +++-
 3rdparty/stout/include/stout/os/raw/argv.hpp      | 4 +---
 3 files changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f86ff5c7/3rdparty/stout/include/stout/os/mktemp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/mktemp.hpp 
b/3rdparty/stout/include/stout/os/mktemp.hpp
index 2e35c73..0b7fe73 100644
--- a/3rdparty/stout/include/stout/os/mktemp.hpp
+++ b/3rdparty/stout/include/stout/os/mktemp.hpp
@@ -34,8 +34,9 @@ namespace os {
 inline Try<std::string> mktemp(const std::string& path = "/tmp/XXXXXX")
 {
   char* temp = new char[path.size() + 1];
-  int fd = ::mkstemp(::strcpy(temp, path.c_str()));
+  ::memcpy(temp, path.c_str(), path.size() + 1);
 
+  int fd = ::mkstemp(temp);
   if (fd < 0) {
     delete[] temp;
     return ErrnoError();

http://git-wip-us.apache.org/repos/asf/mesos/blob/f86ff5c7/3rdparty/stout/include/stout/os/posix/mkdtemp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/mkdtemp.hpp 
b/3rdparty/stout/include/stout/os/posix/mkdtemp.hpp
index 31acbd4..4edfc6b 100644
--- a/3rdparty/stout/include/stout/os/posix/mkdtemp.hpp
+++ b/3rdparty/stout/include/stout/os/posix/mkdtemp.hpp
@@ -29,7 +29,9 @@ namespace os {
 inline Try<std::string> mkdtemp(const std::string& path = "/tmp/XXXXXX")
 {
   char* temp = new char[path.size() + 1];
-  if (::mkdtemp(::strcpy(temp, path.c_str())) != nullptr) {
+  ::memcpy(temp, path.c_str(), path.size() + 1);
+
+  if (::mkdtemp(temp) != nullptr) {
     std::string result(temp);
     delete[] temp;
     return result;

http://git-wip-us.apache.org/repos/asf/mesos/blob/f86ff5c7/3rdparty/stout/include/stout/os/raw/argv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/raw/argv.hpp 
b/3rdparty/stout/include/stout/os/raw/argv.hpp
index 3ac6216..479096a 100644
--- a/3rdparty/stout/include/stout/os/raw/argv.hpp
+++ b/3rdparty/stout/include/stout/os/raw/argv.hpp
@@ -40,9 +40,7 @@ public:
     std::vector<char*> _argv;
     foreach (const std::string& arg, iterable) {
       char* _arg = new char[arg.size() + 1];
-
-      // NOTE: strcpy will fill the terminating `\0' character.
-      strcpy(_arg, arg.c_str());
+      ::memcpy(_arg, arg.c_str(), arg.size() + 1);
       _argv.emplace_back(_arg);
     }
 

Reply via email to