]> sourceware.org Git - systemtap.git/commitdiff
stapbpf/bpfinterp.cxx (map_get_next_key) :: try to pass all warnings
authorSerhei Makarov <smakarov@redhat.com>
Wed, 15 May 2019 20:48:34 +0000 (16:48 -0400)
committerSerhei Makarov <smakarov@redhat.com>
Wed, 15 May 2019 20:51:48 +0000 (16:51 -0400)
turns out RHEL7 gcc did not understand __attribute__ ((nonstring)).
This code has extra paranoia in adding a NUL beyond the area
overwritten by strncpy. Switch from strncpy to memcpy since bpf
syscall is treating everything as opaque memory.

stapbpf/bpfinterp.cxx

index 1481430603bcfa9c4b14440da9a4fc4a44f1bd44..3edb4457532b1c520f55d3727a36be0d62b72292 100644 (file)
@@ -112,17 +112,19 @@ map_get_next_key(int fd_idx, int64_t key, int64_t next_key,
   // with a single map during execution of nested foreach loops.
   if (!key && is_str)
     {
-      // XXX: BPF_MAXSTRINGLEN+1 to placate coverity,
-      // ((nonstring)) to placate gcc9 warnings. Worth reviewing.
-      char k[BPF_MAXSTRINGLEN_PLUS] __attribute__ ((nonstring)),
-        n[BPF_MAXSTRINGLEN_PLUS] __attribute__ ((nonstring));
+      // XXX: copy with memcpy() and add a safety NUL. This avoids
+      // labyrinth of contradictory compiler warnings on different
+      // platforms. Worth reviewing.
+      char k[BPF_MAXSTRINGLEN_PLUS],
+        n[BPF_MAXSTRINGLEN_PLUS];
+      k[BPF_MAXSTRINGLEN] = n[BPF_MAXSTRINGLEN] = '\0';
       std::set<std::string> s;
 
       int rc = bpf_get_next_key(fd, 0, as_ptr(n));
       while (!rc)
         {
-          strncpy(k, n, BPF_MAXSTRINGLEN);
-          s.insert(std::string(k));
+          memcpy(k, n, BPF_MAXSTRINGLEN);
+          s.insert(std::string(k, BPF_MAXSTRINGLEN));
           rc = bpf_get_next_key(fd, as_ptr(k), as_ptr(n));
         }
 
This page took 0.389519 seconds and 5 git commands to generate.