summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@webkeks.org>2015-10-04 13:30:52 +0200
committerJonathan Schleifer <js@webkeks.org>2015-10-04 13:33:02 +0200
commit4886af978c61cac3ee63576d22861b9a44576458 (patch)
tree77e68c4deaf90f3b3e9f1084eb547e76f8b085fa
parent7715da28d484594c6b1872fcdbd6d06c734205d4 (diff)
Better length checks for write / send calls
-rw-r--r--src/OFFile.m9
-rw-r--r--src/OFProcess.m7
-rw-r--r--src/OFStdIOStream.m9
-rw-r--r--src/OFStreamSocket.m9
-rw-r--r--src/OFUDPSocket.m9
5 files changed, 30 insertions, 13 deletions
diff --git a/src/OFFile.m b/src/OFFile.m
index ac2b234a..888427cf 100644
--- a/src/OFFile.m
+++ b/src/OFFile.m
@@ -1090,15 +1090,18 @@ parseMode(const char *mode)
requestedLength: length];
#ifndef _WIN32
- if (write(_fd, buffer, length) < length)
+ if (length > SSIZE_MAX)
+ @throw [OFOutOfRangeException exception];
+
+ if (write(_fd, buffer, length) != (ssize_t)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
#else
- if (length > UINT_MAX)
+ if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
- if (write(_fd, buffer, (unsigned int)length) < length)
+ if (write(_fd, buffer, (int)length) != (int)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
diff --git a/src/OFProcess.m b/src/OFProcess.m
index ce337a7c..2e40ca08 100644
--- a/src/OFProcess.m
+++ b/src/OFProcess.m
@@ -498,7 +498,10 @@ extern char **environ;
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
- if (write(_writePipe[1], buffer, length) < length)
+ if (length > SSIZE_MAX)
+ @throw [OFOutOfRangeException exception];
+
+ if (write(_writePipe[1], buffer, length) != (ssize_t)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
@@ -513,7 +516,7 @@ extern char **environ;
requestedLength: length];
if (!WriteFile(_writePipe[1], buffer, (DWORD)length, &ret, NULL) ||
- ret < length) {
+ ret != (DWORD)length) {
int errNo = 0;
if (GetLastError() == ERROR_BROKEN_PIPE)
diff --git a/src/OFStdIOStream.m b/src/OFStdIOStream.m
index fa543aba..ac06cade 100644
--- a/src/OFStdIOStream.m
+++ b/src/OFStdIOStream.m
@@ -132,15 +132,18 @@ of_log(OFConstantString *format, ...)
requestedLength: length];
#ifndef _WIN32
- if (write(_fd, buffer, length) < length)
+ if (length > SSIZE_MAX)
+ @throw [OFOutOfRangeException exception];
+
+ if (write(_fd, buffer, length) != (ssize_t)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
#else
- if (length > UINT_MAX)
+ if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
- if (write(_fd, buffer, (unsigned int)length) < length)
+ if (write(_fd, buffer, (int)length) != (int)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
diff --git a/src/OFStreamSocket.m b/src/OFStreamSocket.m
index 858ffd0f..bda40ef3 100644
--- a/src/OFStreamSocket.m
+++ b/src/OFStreamSocket.m
@@ -101,16 +101,19 @@
errNo: ENOTCONN];
#ifndef _WIN32
- if (send(_socket, buffer, length, 0) < length)
+ if (length > SSIZE_MAX)
+ @throw [OFOutOfRangeException exception];
+
+ if (send(_socket, buffer, length, 0) != (ssize_t)length)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
errNo: of_socket_errno()];
#else
- if (length > UINT_MAX)
+ if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
- if (send(_socket, buffer, (unsigned int)length, 0) < length)
+ if (send(_socket, buffer, (int)length, 0) != (int)length)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
diff --git a/src/OFUDPSocket.m b/src/OFUDPSocket.m
index 2a9e1c70..bfea058b 100644
--- a/src/OFUDPSocket.m
+++ b/src/OFUDPSocket.m
@@ -541,8 +541,12 @@ of_udp_socket_address_hash(of_udp_socket_address_t *address)
@throw [OFNotOpenException exceptionWithObject: self];
#ifndef _WIN32
+ if (length > SSIZE_MAX)
+ @throw [OFOutOfRangeException exception];
+
if (sendto(_socket, buffer, length, 0,
- (struct sockaddr*)&receiver->address, receiver->length) < length)
+ (struct sockaddr*)&receiver->address,
+ receiver->length) != (ssize_t)length)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
@@ -552,7 +556,8 @@ of_udp_socket_address_hash(of_udp_socket_address_t *address)
@throw [OFOutOfRangeException exception];
if (sendto(_socket, buffer, (int)length, 0,
- (struct sockaddr*)&receiver->address, receiver->length) < length)
+ (struct sockaddr*)&receiver->address,
+ receiver->length) != (int)length)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length