]> sourceware.org Git - systemtap.git/commitdiff
PR24926: correct printing of utf-8 characters on stapbpf
authorSagar Patel <sapatel@redhat.com>
Thu, 29 Aug 2019 15:32:17 +0000 (11:32 -0400)
committerSagar Patel <sapatel@redhat.com>
Tue, 3 Sep 2019 16:47:41 +0000 (12:47 -0400)
There were two bugs corrupting the string bytes and instructions. The
first bug involved the implicit sign extension of negative char values.
The second bug involved a faulty optimization (fixup_operands) which
used the incorrect instruction opcode.

1) Cast char to unsigned char before casting to uint32_t.
2) Changed opcode of optimized instruction to (BPF_STX | BPF_MEM | BPF_W).

bpf-opt.cxx
bpf-translate.cxx

index 5c7acb6b983f524ca425ab9e56316161d5026b34..225d1d746932572abdebb2f3dc2f07a13470aaa3 100644 (file)
@@ -136,7 +136,11 @@ fixup_operands(program &p)
              insn_before_inserter ins(b, j, "opt");
              p.mk_mov(ins, n, s1);
              j->src1 = s1 = n;
-           }
+
+        // Since the content is in the src register, we need
+        // to use BPF_STX instead of BPF_ST
+        j->code = BPF_STX | BPF_MEM | BPF_W; 
+           } 
 
          if (value *s0 = j->src0)
            {
index 2cd097663a6a9fbf36de9d993cd70e6fad26c7b1..11ccd76270ef2a4dae407732c436fda6f616c508 100644 (file)
@@ -2869,8 +2869,13 @@ emit_simple_literal_str(program &this_prog, insn_inserter &this_ins,
         if (i * 4 + j < str_bytes - 1)
           {
             // ??? assuming little-endian target
-            word |= (uint32_t)src[i * 4 + j] << (j * 8);
+            //
+            // Must cast each signed char in src to unsigned char first
+            // in order to avoid the implicit sign extension resulting 
+            // from the uint32_t cast. 
+            word |= ((uint32_t)(unsigned char)src[i * 4 + j]) << (j * 8);
           }
+
       this_prog.mk_st(this_ins, BPF_W,
                       dest, (int32_t)i * 4 + ofs,
                       this_prog.new_imm(word));
This page took 0.031539 seconds and 5 git commands to generate.