summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Janc <szymon@janc.net.pl>2012-06-13 22:49:19 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2012-06-14 14:31:48 +0300
commit9363c39d6f87f3963a279b746144ecd18d770c7d (patch)
treed113779f67e927aaf5818e1dbc7d314a15f65958
parent962f0c10430ff0bd615e23ed36287da97de09f0d (diff)
downloadobexd-9363c39d6f87f3963a279b746144ecd18d770c7d.tar.gz
client: Fix error returning in obc_transfer_put
Always set error on failure in obc_transfer_put. This is expected by callers and will avoid possible NULL pointer dereference. Also fix improper use of errno variable (calling error may modify it) and some dead assignments to perr.
-rw-r--r--client/transfer.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/client/transfer.c b/client/transfer.c
index cb7c26c..76f6681 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -419,12 +419,15 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
w = write(transfer->fd, contents, size);
if (w < 0) {
- error("write(): %s(%d)", strerror(errno), errno);
- perr = -errno;
+ perr = errno;
+ error("write(): %s(%d)", strerror(perr), perr);
+ g_set_error(err, OBC_TRANSFER_ERROR, -perr,
+ "Writing to file failed");
goto fail;
} else if ((size_t) w != size) {
error("Unable to write all contents to file");
- perr = -EFAULT;
+ g_set_error(err, OBC_TRANSFER_ERROR, -EFAULT,
+ "Writing all contents to file failed");
goto fail;
}
} else {
@@ -432,10 +435,10 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
goto fail;
}
- perr = fstat(transfer->fd, &st);
- if (perr < 0) {
- error("fstat(): %s(%d)", strerror(errno), errno);
- g_set_error(err, OBC_TRANSFER_ERROR, -errno,
+ if (fstat(transfer->fd, &st) < 0) {
+ perr = errno;
+ error("fstat(): %s(%d)", strerror(perr), perr);
+ g_set_error(err, OBC_TRANSFER_ERROR, -perr,
"Unable to get file status");
goto fail;
}