History

nfsd: escape high characters in binary data

I'm exposing some information about NFS clients in pseudofiles. I expect to eventually have simple tools to help read those pseudofiles. But it's also helpful if the raw files are human-readable to the extent possible. It aids debugging and makes them usable on systems that don't have the latest nfs-utils. A minor challenge there is opaque client-generated protocol objects like state owners and client identifiers. Some clients generate those to include handy information in plain ascii. But they may also include arbitrary byte sequences. I think the simplest approach is to limit to isprint(c) && isascii(c) and escape everything else. That means you can just cat the file and get something that looks OK. Also, I'm trying to keep these files legal YAML, which requires them to UTF-8, and this is a simple way to guarantee that.

J. Bruce Fields committed 7 years ago

Commit ea053e11 parent 3bade244 files · +34 −0Browse files

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/seq_file.h +1 −0
  2. include/linux/string_helpers.h +3 −0
include/linux/seq_file.h+1−0
@@ -127,6 +127,7 @@ void seq_put_hex_ll(struct seq_file *m, const char *delimiter, · 126 unmodified lines
127 unsigned long long v, unsigned int width);127 unsigned long long v, unsigned int width);
128 128
129void seq_escape(struct seq_file *m, const char *s, const char *esc);129void seq_escape(struct seq_file *m, const char *s, const char *esc);
130void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz);
130 131
131void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,132void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
132 int rowsize, int groupsize, const void *buf, size_t len,133 int rowsize, int groupsize, const void *buf, size_t len,
include/linux/string_helpers.h+3−0
@@ -54,6 +54,9 @@ static inline int string_unescape_any_inplace(char *buf) · 53 unmodified lines
54int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,54int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
55 unsigned int flags, const char *only);55 unsigned int flags, const char *only);
56 56
57int string_escape_mem_ascii(const char *src, size_t isz, char *dst,
58 size_t osz);
59
57static inline int string_escape_mem_any_np(const char *src, size_t isz,60static inline int string_escape_mem_any_np(const char *src, size_t isz,
58 char *dst, size_t osz, const char *only)61 char *dst, size_t osz, const char *only)
59{62{

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t