[patch] NUL in strings (was: Marshalling bytewise data with Glib bindings)

Simon McVittie simon.mcvittie at collabora.co.uk
Mon May 21 02:50:03 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 21 May 2007 at 07:01:18 +0200, Thiago Macieira wrote:
> STRING should be used only for properly-encoded UTF-8 data. NULs are 
> allowed, but arbitrary binary data isn't.

My understanding is that NULs are not allowed in STRING (and that it's
terminated with a NUL, but that's not semantically part of the data). IMO the
specification could be interpreted either way, but libdbus doesn't appear to
support NUL-safe strings:

* dbus_message_iter_append_basic() stops appending at NUL
* dbus_message_iter_get_basic() doesn't indicate the length

Havoc/other designers, did you intend the STRING type to be NUL-safe? If
so, libdbus needs extra API and the spec needs clarifying to allow NULs;
if not (as I suspect), the spec needs clarifying to forbid NULs.
A proposed patch for the latter case follows.

	Simon


Index: doc/dbus-specification.xml
===================================================================
RCS file: /cvs/dbus/dbus/doc/dbus-specification.xml,v
retrieving revision 1.49
diff -u -r1.49 dbus-specification.xml
- --- doc/dbus-specification.xml	4 May 2007 10:28:12 -0000	1.49
+++ doc/dbus-specification.xml	21 May 2007 09:48:43 -0000
@@ -385,7 +385,7 @@
               </row><row>
                 <entry><literal>STRING</literal></entry>
                 <entry>115 (ASCII 's')</entry>
- -                <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be nul terminated.</entry>
+                <entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be nul terminated and contain no other nul bytes.</entry>
               </row><row>
                 <entry><literal>OBJECT_PATH</literal></entry>
                 <entry>111 (ASCII 'o')</entry>
@@ -503,7 +503,7 @@
                 <entry><literal>STRING</literal></entry>
                 <entry>A <literal>UINT32</literal> indicating the string's 
                   length in bytes excluding its terminating nul, followed by 
- -                  string data of the given length, followed by a terminating nul 
+                  non-nul string data of the given length, followed by a terminating nul 
                   byte.
                 </entry>
                 <entry>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net

iD8DBQFGUWtLWSc8zVUw7HYRAtanAKDESn8mMj1+jHHWnhh+V4FxYg/PlwCgxnT0
DImHSeH2gSWYx3h6i+wHShw=
=+Lgi
-----END PGP SIGNATURE-----


More information about the dbus mailing list