Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/69677?usp=email )

Change subject: base: fatal() if a socket path doesn't fit in sockaddr_un.sun_path.
......................................................................

base: fatal() if a socket path doesn't fit in sockaddr_un.sun_path.

Normally this would just generate a warning, but a warning is easy to
miss, and truncating the path to fit would be surprising. Since the max
length isn't likely to change, a path which has to be truncated is
essentially fundementally wrong, and could be defined as something
else which is short enough before being used in the config.

Note that this only applies to either the abstract path which is just
a string, or the file name and not the directory path on a file based
socket.

Change-Id: I8702cf02c03053b5d0b6133f25b0e588de666f15
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69677
Maintainer: Gabe Black <gabebl...@google.com>
Reviewed-by: Earl Ou <shunhsin...@google.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/socket.cc
M src/base/socket.hh
2 files changed, 10 insertions(+), 13 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass
  Earl Ou: Looks good to me, approved




diff --git a/src/base/socket.cc b/src/base/socket.cc
index 76dc73f..62f2071 100644
--- a/src/base/socket.cc
+++ b/src/base/socket.cc
@@ -261,15 +261,12 @@
     });
 }

-std::string
-ListenSocketUnix::truncate(const std::string &original, size_t max_len)
+void
+ListenSocketUnix::checkPathLength(const std::string &original, size_t max_len)
 {
-    if (original.size() <= max_len)
-        return original;
-
-    std::string truncated = original.substr(0, max_len);
-    warn("%s: Truncated \"%s\" to \"%s\"", name(), original, truncated);
-    return truncated;
+    fatal_if(original.size() > max_len,
+            "Length of socket path '%s' is %d, greater than max %d.",
+            original, original.size(), max_len);
 }

 void
@@ -303,9 +300,9 @@

 ListenSocketUnixFile::ListenSocketUnixFile(const std::string &_name,
         const std::string &_dir, const std::string &_fname) :
-    ListenSocketUnix(_name), dir(_dir),
-    fname(truncate(_fname, sizeof(sockaddr_un::sun_path) - 1))
+    ListenSocketUnix(_name), dir(_dir), fname(_fname)
 {
+    checkPathLength(fname, sizeof(sockaddr_un::sun_path) - 1);
 }

 ListenSocketUnixFile::~ListenSocketUnixFile()
@@ -385,9 +382,9 @@

 ListenSocketUnixAbstract::ListenSocketUnixAbstract(
         const std::string &_name, const std::string &_path) :
-    ListenSocketUnix(_name),
-    path(truncate(_path, sizeof(sockaddr_un::sun_path) - 1))
+    ListenSocketUnix(_name), path(_path)
 {
+    checkPathLength(path, sizeof(sockaddr_un::sun_path) - 1);
 }

 void
diff --git a/src/base/socket.hh b/src/base/socket.hh
index b8828e7..bc17213 100644
--- a/src/base/socket.hh
+++ b/src/base/socket.hh
@@ -162,7 +162,7 @@
   protected:
     virtual size_t prepSockaddrUn(sockaddr_un &addr) const = 0;

-    std::string truncate(const std::string &original, size_t max_len);
+    void checkPathLength(const std::string &original, size_t max_len);

     ListenSocketUnix(const std::string &_name) : ListenSocket(_name) {}


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/69677?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I8702cf02c03053b5d0b6133f25b0e588de666f15
Gerrit-Change-Number: 69677
Gerrit-PatchSet: 2
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Chia-You Chen <hort...@google.com>
Gerrit-Reviewer: Earl Ou <shunhsin...@google.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Jesse Pai <jesse...@google.com>
Gerrit-Reviewer: Yu-hsin Wang <yuhsi...@google.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to