You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2024/03/20 19:05:24 UTC

(mesos) branch master updated: [ebpf] Fix clang-tidy false positive.

This is an automated email from the ASF dual-hosted git repository.

bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new cdc9add29 [ebpf] Fix clang-tidy false positive.
cdc9add29 is described below

commit cdc9add29d0539a661cf5a9af9241676fd6180ae
Author: Benjamin Mahler <bm...@apache.org>
AuthorDate: Wed Mar 20 15:02:52 2024 -0400

    [ebpf] Fix clang-tidy false positive.
    
    We need to figure out the length of the verifier logs by scanning
    for the first \0 byte, our current approach trips a clang-tidy
    warning. This patch should silence it, by instead resizing the
    string down appropriately and using the string directly.
---
 src/linux/ebpf.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/linux/ebpf.cpp b/src/linux/ebpf.cpp
index c280c9114..3f7f74df2 100644
--- a/src/linux/ebpf.cpp
+++ b/src/linux/ebpf.cpp
@@ -19,6 +19,7 @@
 #include <linux/bpf.h>
 #include <sys/syscall.h>
 
+#include <cstring>
 #include <string>
 #include <vector>
 
@@ -91,9 +92,10 @@ Try<int> load(const Program& program)
     CHECK_ERROR(fd);
     CHECK_EQ(EACCES, fd.error().code)
       << "Expected BPF syscall to fail again with EACCES";
-    // Convert `verifier_logs` to a C string to avoid outputting
-    // the zeroed bytes.
-    return Error(string("BPF verifier failed: ") + verifier_logs.data());
+
+    // Truncate the verifier logs based on how many bytes were written.
+    verifier_logs.resize(strlen(verifier_logs.data()));
+    return Error("BPF verifier failed: " + verifier_logs);
   }
 
   if (fd.isError()) {