The Short Story
Unfortunately, unless etcdctl
is extended to explicitly support accepting escaped contents, and unescaping that content to get the key name to use (or to accept key names passed via a means other than the command line), passing a key name containing a literal NUL is not possible.
Consider writing your own command-line client for etcd that accepts encoded strings if this is something you need to do.
Background: How Programs Start Programs On UNIX
When a program starts another program on UNIX, the process involves a syscall called execve()
(or an equivalent: there are higher-level tools like the POSIX spawn() family, but they still act similarly for our purposes here). This might look like:
pid = execve("/usr/bin/etcd", char[][]{
"etcd",
"--endpoints=server:2379",
/* other content here elided */
"get",
keyname
}, environment)
Because this API is defined in C, all strings are NUL-terminated C strings; they start at the character that an individual char*
points to, and end at the next NUL after that character (so when you type "get"
in C, it creates an array like {"g", "e", "t", NULL}
).
Thus, if you have something that actually looks like {"g", "e", "t", NULL, "f", "o", "o", NULL}
, only get
is part of the string starting to the g
; there needs to be another pointer to the f
in foo
for foo
to be seen as a separate argument, and there's no possible way for get\x00foo
to be seen as a single string with \x00
representing a single-byte NUL literal by anything written to interact with C-style strings.