diff options
author | Russ Allbery <rra@stanford.edu> | 2008-02-12 01:55:09 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2008-02-12 01:55:09 +0000 |
commit | 54ccb6083d69da03c71d01a271a09554e4d63e4f (patch) | |
tree | edfacb2be7a6737ffe1421bde013ab101adadd44 /client | |
parent | 8981930051a7876586de885183bb0997e9800b3c (diff) |
Correctly handle get of an empty object in the wallet client. The
empty string is valid object content.
Add a full end-to-end test suite to catch protocol mismatches between
the client and server, such as the one fixed in this release.
Diffstat (limited to 'client')
-rw-r--r-- | client/file.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/client/file.c b/client/file.c index 17f0f23..10304e5 100644 --- a/client/file.c +++ b/client/file.c @@ -32,11 +32,13 @@ overwrite_file(const char *name, const void *data, size_t length) fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) sysdie("open of %s failed", name); - status = write(fd, data, length); - if (status < 0) - sysdie("write to %s failed", name); - else if (status != (ssize_t) length) - die("write to %s truncated", name); + if (length > 0) { + status = write(fd, data, length); + if (status < 0) + sysdie("write to %s failed", name); + else if (status != (ssize_t) length) + die("write to %s truncated", name); + } if (close(fd) < 0) sysdie("close of %s failed (file probably truncated)", name); } @@ -93,15 +95,17 @@ get_file(struct remctl *r, const char *prefix, const char *type, status = run_command(r, command, &data, &length); if (status != 0) return status; - if (data == NULL) { - warn("no data returned by wallet server"); - return 255; - } + + /* The empty string is valid data. */ + if (data == NULL) + length = 0; if (file != NULL) write_file(file, data, length); - else { + else if (length > 0) { if (fwrite(data, length, 1, stdout) != 1) sysdie("cannot write to standard output"); } + if (data != NULL) + free(data); return 0; } |