dbus-send knows how to pretty-print byte arrays that only contain ASCII characters, which are sometimes used to represent filenames or other not-guaranteed-to-be-UTF-8 strings. However, it can't currently pretty-print the encoding advocated by the GVariant developers, which is the string plus a trailing \0, again as a byte array. This encoding has the advantage that callers can read it directly from the message as a C string without copying.
Created attachment 113418 [details] [review] dbus-send: pretty-print GVariant-style bytestrings dbus-send could already pretty-print bytestrings that do not have \0 termination, but those are awkward to work with (they need copying), so they are now discouraged. Teach it to print bytestrings that do have \0 termination as well. In the process, rewrite this part of the message parser to use dbus_message_iter_get_fixed_array(), which is the Right way to get arrays of numbers out of a message. --- In particular, this makes Bug #89041 work a lot nicer with dbus-send: LinuxSecurityLabel comes out as 'array of bytes with \0 termination "/usr/sbin/connmand (complain)"' rather than 'array of bytes [ 2f 75 ... ]'.
Comment on attachment 113418 [details] [review] dbus-send: pretty-print GVariant-style bytestrings Review of attachment 113418 [details] [review]: ----------------------------------------------------------------- ::: tools/dbus-print-message.c @@ +117,1 @@ > dbus_bool_t all_ascii = TRUE; Maybe rename this to all_ascii_with_nul_terminator, or add a comment to that effect? (I realise \0 is ASCII, but it’s not normal for an ASCII string.) @@ +132,2 @@ > { > + printf ("array of bytes with \\0 termination \"%s\"\n", bytes); ‘array of nul-terminated bytes’ is shorter.
I try to avoid talking about NUL as a synonym for \0, because NUL and NULL are not the same thing. How about this? \0-terminated array of bytes "hello" which is even shorter :-)
(In reply to Simon McVittie from comment #3) > How about this? > > \0-terminated array of bytes "hello" > > which is even shorter :-) I thought about that, but decided against it because it doesn’t start with ‘array’, which I suspect is useful for quickly scanning through output.
Some more possible colours to paint this bike shed: array of bytes "hello" + \0 bytestring "hello" array of \0-terminated bytes "hello" array of bytes, \0-terminated "hello" I didn't initially like the first option (or similar) because I was worried you could make it ambiguous with a bytestring like 'hello" + \\0\n...' but we don't count \n as printable ASCII, so if we deliberately avoid enclosing the \0 in quotes, it is unambiguous: "\\0\n" in the output is definitely not part of the quoted string. As a result, I think I like this option best. The second option is very concise, but I'm concerned that people might not make the connection that a "bytestring" (GVariant jargon for an 'ay' with \0 termination and no embedded \0 in the value) is an 'ay'. The third and fourth are not much better than the ones we've each suggested previously.
Created attachment 113480 [details] [review] dbus-send: pretty-print GVariant-style bytestrings --- Changes since v1: * print bytestrings as 'array of bytes "hello" + \0' * fix out-of-bounds read for 0-length byte arrays (which are still printed as 'array of bytes ""', as they were before this patch) * add comment as requested * use dbus_malloc, dbus_free to integrate with libdbus debug glue * early-break out of loop when we find an unprintable byte
Comment on attachment 113480 [details] [review] dbus-send: pretty-print GVariant-style bytestrings Review of attachment 113480 [details] [review]: ----------------------------------------------------------------- ++
Thanks, fixed in git for 1.9.12
Created attachment 113536 [details] [review] Keep cmake build system in sync with autotools
Pushed Ralf's additional patch for 1.9.12, thanks.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.