Bug 501889 - write-file does not support strings containing ASCII NUL
write-file does not support strings containing ASCII NUL
Product: Virtualization Tools
Classification: Community
Component: libguestfs (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Richard W.M. Jones
Depends On:
Blocks: 592883
  Show dependency treegraph
Reported: 2009-05-21 04:46 EDT by Richard W.M. Jones
Modified: 2011-07-14 15:09 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2011-07-14 15:09:43 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Richard W.M. Jones 2009-05-21 04:46:57 EDT
The guestfs_write_file / write-file command uses an XDR
string type to pass the buffer content.  Unfortunately we
discovered after making this choice that XDR strings cannot
contain ASCII NUL characters, which means that write-file
cannot be used to write binary files.

Current workaround is to use the guestfs_upload command
instead to upload arbitrary binary files to the guest filesystem.

We need to implement BufferIn/Out parameters, as discussed
in the TODO file.
Comment 1 Mark McLoughlin 2009-05-25 10:49:58 EDT
Moving upstream, since it's a "known limitiation" with the API which has a workaround
Comment 2 Richard W.M. Jones 2010-05-17 06:35:00 EDT
I'll make an extended attempt at explaining what this bug
is all about, since it affects FUSE access (bug 592883).

In libguestfs there is a protocol which is used to send and
receive messages between the library and the daemon (which
runs inside qemu).  This protocol uses Sun XDR, the same basic
protocol as NFS, NIS etc.

In the protocol, we normally encode C 'char *' as the XDR
string type.  When we first implemented this we didn't realize
that these are C strings, terminated by \0 characters.  (This
is because at the protocol level, they _are_ sent as len word +
data, but the C-level XDR library has the limitation that it
works out the length word using strlen).

Anyway, we need to use the XDR 'opaque' type.  It's exactly
the same as 'string' at the wire level, but in the XDR library
it is encoded using an explicit length, and therefore it can
contain \0 bytes.

To avoid complicating existing string parameters, we need
to add to the generator a new arg type, BufferIn, which will
take a (const char *, size_t) pair and send an opaque value
over the wire.

This will allow us to fix write-file, and implement a pwrite
API.  (Currently it's not possible to implement the pwrite
call in the API because it would fail if the buffer being
written contained any \0 byte).

With a pwrite call, we could implement the FUSE write
system call.
Comment 3 Richard W.M. Jones 2010-05-18 17:06:22 EDT
Proposed fix posted upstream:

Note You need to log in before you can comment on or make changes to this bug.