summaryrefslogtreecommitdiff
path: root/obexd/client
diff options
context:
space:
mode:
authorSzymon Janc <szymon@janc.net.pl>2012-06-13 22:49:19 +0200
committerMarcel Holtmann <marcel@holtmann.org>2012-12-04 22:49:03 +0100
commit20340654cf4221da492cc5bc26764dfba5f80c9b (patch)
tree6ec0dbf125dadf327542695c64c968beaa83e306 /obexd/client
parente1713aa11d83c30531ed503ec59dab94de43f87f (diff)
downloadbluez-20340654cf4221da492cc5bc26764dfba5f80c9b.tar.gz
obexd: 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.
Diffstat (limited to 'obexd/client')
-rw-r--r--obexd/client/transfer.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/obexd/client/transfer.c b/obexd/client/transfer.c
index cb7c26c21..76f6681fd 100644
--- a/obexd/client/transfer.c
+++ b/obexd/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;
}