]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bpf: Support "%c" in bpf_bprintf_prepare().
authorKuniyuki Iwashima <kuniyu@amazon.co.jp>
Sat, 14 Aug 2021 01:57:16 +0000 (10:57 +0900)
committerAndrii Nakryiko <andrii@kernel.org>
Sun, 15 Aug 2021 07:13:33 +0000 (00:13 -0700)
/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
kernel/bpf/helpers.c

index 32761be4814304b9d0ce7a6e72d64bc72649f718..4e8540716187fd9d0f9d22e3e9d0f5a805b1528a 100644 (file)
@@ -907,6 +907,20 @@ fmt_str:
                        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;
                }