Bug 89109 - dbus-send: pretty-print GVariant-style bytestrings
Summary: dbus-send: pretty-print GVariant-style bytestrings
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: git master
Hardware: Other All
: medium enhancement
Assignee: Simon McVittie
QA Contact: D-Bus Maintainers
URL:
Whiteboard: review?
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-02-12 18:48 UTC by Simon McVittie
Modified: 2015-02-16 14:00 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
dbus-send: pretty-print GVariant-style bytestrings (3.38 KB, patch)
2015-02-12 18:58 UTC, Simon McVittie
Details | Splinter Review
dbus-send: pretty-print GVariant-style bytestrings (3.62 KB, patch)
2015-02-13 19:49 UTC, Simon McVittie
Details | Splinter Review
Keep cmake build system in sync with autotools (762 bytes, patch)
2015-02-16 13:47 UTC, Ralf Habacker
Details | Splinter Review

Description Simon McVittie 2015-02-12 18:48:15 UTC
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.
Comment 1 Simon McVittie 2015-02-12 18:58:05 UTC
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 2 Philip Withnall 2015-02-13 08:55:46 UTC
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.
Comment 3 Simon McVittie 2015-02-13 10:09:50 UTC
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 :-)
Comment 4 Philip Withnall 2015-02-13 10:33:05 UTC
(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.
Comment 5 Simon McVittie 2015-02-13 11:24:44 UTC
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.
Comment 6 Simon McVittie 2015-02-13 19:49:49 UTC
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 7 Philip Withnall 2015-02-16 08:53:20 UTC
Comment on attachment 113480 [details] [review]
dbus-send: pretty-print GVariant-style bytestrings

Review of attachment 113480 [details] [review]:
-----------------------------------------------------------------

++
Comment 8 Simon McVittie 2015-02-16 12:24:29 UTC
Thanks, fixed in git for 1.9.12
Comment 9 Ralf Habacker 2015-02-16 13:47:49 UTC
Created attachment 113536 [details] [review]
Keep cmake build system in sync with autotools
Comment 10 Simon McVittie 2015-02-16 14:00:24 UTC
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.