Overview
| Comment: | Better length checks for write / send calls |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | 0.8 |
| Files: | files | file ages | folders |
| SHA3-256: |
ad4e727d5bc0e8a899a4dd6892985c6f |
| User & Date: | js on 2015-10-04 11:33:02 |
| Other Links: | branch diff | manifest | tags |
Context
|
2015-10-04
| ||
| 11:55 | Move OF_ASSUME_NONNULL_BEGIN after all includes (check-in: 7ec3bb7673 user: js tags: 0.8) | |
| 11:33 | Better length checks for write / send calls (check-in: ad4e727d5b user: js tags: 0.8) | |
| 11:12 | Special cases for the Wii's weird network stack (check-in: 3f87c28a33 user: js tags: 0.8) | |
Changes
Modified src/OFFile.m from [768cc854c3] to [8dedd52409].
| ︙ | ︙ | |||
1086 1087 1088 1089 1090 1091 1092 |
length: (size_t)length
{
if (_fd == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
#ifndef _WIN32
| > > > | | | | 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 |
length: (size_t)length
{
if (_fd == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
#ifndef _WIN32
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 > INT_MAX)
@throw [OFOutOfRangeException exception];
if (write(_fd, buffer, (int)length) != (int)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
#endif
}
- (of_offset_t)lowlevelSeekToOffset: (of_offset_t)offset
|
| ︙ | ︙ |
Modified src/OFProcess.m from [dc696d6c83] to [09488f3c9c].
| ︙ | ︙ | |||
494 495 496 497 498 499 500 |
length: (size_t)length
{
#ifndef _WIN32
if (_writePipe[1] == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
| > > > | | | 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
length: (size_t)length
{
#ifndef _WIN32
if (_writePipe[1] == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: 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];
#else
DWORD ret;
if (length > UINT32_MAX)
@throw [OFOutOfRangeException exception];
if (_writePipe[1] == NULL || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
if (!WriteFile(_writePipe[1], buffer, (DWORD)length, &ret, NULL) ||
ret != (DWORD)length) {
int errNo = 0;
if (GetLastError() == ERROR_BROKEN_PIPE)
errNo = EPIPE;
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
|
| ︙ | ︙ |
Modified src/OFStdIOStream.m from [a3654b4d40] to [8e10193c2f].
| ︙ | ︙ | |||
128 129 130 131 132 133 134 |
length: (size_t)length
{
if (_fd == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
#ifndef _WIN32
| > > > | | | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
length: (size_t)length
{
if (_fd == -1 || _atEndOfStream)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length];
#ifndef _WIN32
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 > INT_MAX)
@throw [OFOutOfRangeException exception];
if (write(_fd, buffer, (int)length) != (int)length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
errNo: errno];
#endif
}
- (int)fileDescriptorForReading
|
| ︙ | ︙ |
Modified src/OFStreamSocket.m from [d996f514e3] to [5f9b6a238d].
| ︙ | ︙ | |||
97 98 99 100 101 102 103 | if (_atEndOfStream) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: ENOTCONN]; #ifndef _WIN32 | > > > | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | if (_atEndOfStream) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: ENOTCONN]; #ifndef _WIN32 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 > INT_MAX) @throw [OFOutOfRangeException exception]; if (send(_socket, buffer, (int)length, 0) != (int)length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length errNo: of_socket_errno()]; #endif } |
| ︙ | ︙ |
Modified src/OFUDPSocket.m from [182b0b3dfd] to [3c90c2bfad].
| ︙ | ︙ | |||
537 538 539 540 541 542 543 544 |
length: (size_t)length
receiver: (const of_udp_socket_address_t*)receiver
{
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
#ifndef _WIN32
if (sendto(_socket, buffer, length, 0,
| > > > | > | > | 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 |
length: (size_t)length
receiver: (const of_udp_socket_address_t*)receiver
{
if (_socket == INVALID_SOCKET)
@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) != (ssize_t)length)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
errNo: of_socket_errno()];
#else
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if (sendto(_socket, buffer, (int)length, 0,
(struct sockaddr*)&receiver->address,
receiver->length) != (int)length)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
errNo: of_socket_errno()];
#endif
}
|
| ︙ | ︙ |