[PATCH obexd 3/7] client: Fix error returning in obc_transfer_put

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---
 client/transfer.c |   17 ++++++++++-------
 1 file 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;
 	}
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux