Skip to content

Commit

Permalink
remove obsolete size restriction on port messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Dec 5, 2023
1 parent 05c1ba2 commit aec85c5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 56 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2023-12-05 Richard Frith-Macdonald <[email protected]>

* 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 <[email protected]>

* Source/NSBundle.m:
Expand Down
42 changes: 13 additions & 29 deletions Source/NSMessagePort.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];}
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 12 additions & 27 deletions Source/NSSocketPort.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit aec85c5

Please sign in to comment.