diff --git a/ChangeLog b/ChangeLog index c6512eb812..f148096179 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-12-05 Richard Frith-Macdonald + + * Source/NSMessagePort.m: + * Source/NSSocketPort.m: + Remove obsolete restriction on DO message length. Add exception handler + to invalidate port if we are unable to allocate more memory for a very + large port message. + 2023-11-23 Richard Frith-Macdonald * Source/NSBundle.m: diff --git a/Source/NSMessagePort.m b/Source/NSMessagePort.m index 70d75f7bcc..4a3b65f9ec 100644 --- a/Source/NSMessagePort.m +++ b/Source/NSMessagePort.m @@ -103,11 +103,6 @@ @interface NSProcessInfo (private) + (BOOL) _exists: (int)pid; @end -/* - * Largest chunk of data possible in DO - */ -static uint32_t maxDataLength = 32 * 1024 * 1024; - #if 0 #define M_LOCK(X) {NSDebugMLLog(@"NSMessagePort",@"lock %@",X); [X lock];} #define M_UNLOCK(X) {NSDebugMLLog(@"NSMessagePort",@"unlock %@",X); [X unlock];} @@ -580,15 +575,20 @@ - (void) receivedEvent: (void*)data else { want = [rData length]; - if (want < rWant) + if (want < MAX(rWant, NETBLOCK)) { - want = rWant; - [rData setLength: want]; - } - if (want < NETBLOCK) - { - want = NETBLOCK; - [rData setLength: want]; + want = MAX(rWant, NETBLOCK); + NS_DURING + { + [rData setLength: want]; + } + NS_HANDLER + { + M_UNLOCK(myLock); + [self invalidate]; + [localException raise]; + } + NS_ENDHANDLER } } @@ -682,14 +682,6 @@ - (void) receivedEvent: (void*)data } else { - if (l > maxDataLength) - { - NSLog(@"%@ - unreasonable length (%u) for data", - self, l); - M_UNLOCK(myLock); - [self invalidate]; - return; - } /* * If not a port or zero length data, * we discard the data read so far and fill the @@ -705,14 +697,6 @@ - (void) receivedEvent: (void*)data } else if (rType == GSP_HEAD) { - if (l > maxDataLength) - { - NSLog(@"%@ - unreasonable length (%u) for data", - self, l); - M_UNLOCK(myLock); - [self invalidate]; - return; - } /* * If not a port or zero length data, * we discard the data read so far and fill the diff --git a/Source/NSSocketPort.m b/Source/NSSocketPort.m index 6eedb276d0..83e8434526 100644 --- a/Source/NSSocketPort.m +++ b/Source/NSSocketPort.m @@ -139,11 +139,6 @@ static int socketError() } #endif /* !_WIN32 */ -/* - * Largest chunk of data possible in DO - */ -static uint32_t maxDataLength = 32 * 1024 * 1024; - /* Options for TLS encryption of connections */ static NSDictionary *tlsClientOptions; @@ -883,15 +878,19 @@ - (void) receivedEventRead else { want = [rData length]; - if (want < rWant) - { - want = rWant; - [rData setLength: want]; - } - if (want < NETBLOCK) + if (want < MAX(rWant, NETBLOCK)) { - want = NETBLOCK; - [rData setLength: want]; + want = MAX(rWant, NETBLOCK); + NS_DURING + { + [rData setLength: want]; + } + NS_HANDLER + { + [self invalidate]; + [localException raise]; + } + NS_ENDHANDLER } } @@ -1013,13 +1012,6 @@ - (void) receivedEventRead } else { - if (l > maxDataLength) - { - NSLog(@"%@ - unreasonable length (%u) for data", - self, l); - [self invalidate]; - return; - } /* * If not a port or zero length data, * we discard the data read so far and fill the @@ -1035,13 +1027,6 @@ - (void) receivedEventRead } else if (rType == GSP_HEAD) { - if (l > maxDataLength) - { - NSLog(@"%@ - unreasonable length (%u) for data", - self, l); - [self invalidate]; - return; - } /* * If not a port or zero length data, * we discard the data read so far and fill the