Skip to content

Instantly share code, notes, and snippets.

@fbs
Created November 20, 2019 08:34
Show Gist options
  • Select an option

  • Save fbs/b5fd44db65ee9656d933e5bd9943bd55 to your computer and use it in GitHub Desktop.

Select an option

Save fbs/b5fd44db65ee9656d933e5bd9943bd55 to your computer and use it in GitHub Desktop.
```
Attaching 1 probe...
Input: text1
Input: text2
Input: text3
Input: text1
bpf got: 5 text1
bpf got: 5 text2
bpf got: 5 text3
bpf got: 5 text1
```
This works because the `str` call sets an upper bound, `min(arg1, 64)`:
```
14: (07) r2 += 1
15: (b7) r3 = 64
16: (2d) if r3 > r2 goto pc+1
17: (b7) r2 = 64
```
uprobe:./dale:fn {
printf("bpf got: %d %s\n", arg1, str(arg0, arg1));
}
// compile with gcc -O0 test.c -o dale -g
#include <stdio.h>
#include <string.h>
int fn(char * b, size_t len) {
char buf[256] = {0};
len = len > 255 ? 255 : len;
strncpy(buf, b, len);
buf[len] = '\0';
printf("Input: %s\n", buf);
}
int main(void) {
char buf[1024] = "text1text2text3";
strncpy(buf+1000, buf, 5);
fn(buf, 5);
fn(buf+5, 5);
fn(buf+10, 5);
fn(buf+1000, 5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment