Skip to content

Commit

Permalink
bpf: Support "%c" in bpf_bprintf_prepare().
Browse files Browse the repository at this point in the history
/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in
the name of the abstract UNIX domain socket.  The following selftest uses
it, so this patch adds support for "%c".  Note that it does not support
wide character ("%lc" and "%llc") for simplicity.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210814015718.42704-3-kuniyu@amazon.co.jp
  • Loading branch information
Kuniyuki Iwashima authored and Andrii Nakryiko committed Aug 15, 2021
1 parent 2c860a4 commit 3478cfc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kernel/bpf/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,20 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
tmp_buf += err;
num_spec++;

continue;
} else if (fmt[i] == 'c') {
if (!tmp_buf)
goto nocopy_fmt;

if (tmp_buf_end == tmp_buf) {
err = -ENOSPC;
goto out;
}

*tmp_buf = raw_args[num_spec];
tmp_buf++;
num_spec++;

continue;
}

Expand Down

0 comments on commit 3478cfc

Please sign in to comment.