Skip to content

Commit

Permalink
Clamp socket port and fix issue with removing from chat
Browse files Browse the repository at this point in the history
  • Loading branch information
tneotia committed Aug 26, 2022
1 parent def75f4 commit 7d07f5c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MacOS-10/BlueBubblesHelper/BlueBubblesHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
}
NSArray<IMHandle*> *handles = [[IMHandleRegistrar sharedInstance] getIMHandlesForID:(data[@"address"])];

if (handles != nil) {
if (handles == nil) {
if (transaction != nil) {
[[NetworkController sharedInstance] sendMessage: @{@"transactionId": transaction, @"error": @"Failed to load handles for provided address!"}];
}
Expand Down
9 changes: 8 additions & 1 deletion MacOS-10/BlueBubblesHelper/NetworkController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ + (NetworkController*)sharedInstance {

#pragma mark - Public methods

#define CLAMP(x, low, high) ({\
__typeof__(x) __x = (x); \
__typeof__(low) __low = (low);\
__typeof__(high) __high = (high);\
__x > __high ? __high : (__x < __low ? __low : __x);\
})

- (void)connect {
// we need to get the port to open the server on (to allow multiple users to use the bundle)
// we'll base this off the users uid (a unique id for each user, starting from 501)
// we'll subtract 501 to get an id starting at 0, incremented for each user
// then we add this to the base port to get a unique port for the socket
int port = 45670 + getuid()-501;
int port = CLAMP(45670 + getuid()-501, 45670, 65535);
DLog(@"BLUEBUBBLESHELPER: Connecting to socket on port %d", port);
// connect to socket
asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
Expand Down
8 changes: 4 additions & 4 deletions MacOS-11+/BlueBubblesHelper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEPLOYMENT_LOCATION = YES;
DEVELOPMENT_TEAM = S6D73TBQQU;
DSTROOT = /;
Expand All @@ -483,7 +483,7 @@
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.0.5;
MARKETING_VERSION = 0.0.6;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.bluebubbles.messaging;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -504,7 +504,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEPLOYMENT_LOCATION = YES;
DEVELOPMENT_TEAM = S6D73TBQQU;
DSTROOT = /;
Expand All @@ -519,7 +519,7 @@
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.0.5;
MARKETING_VERSION = 0.0.6;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.bluebubbles.messaging;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion MacOS-11+/BlueBubblesHelper/BlueBubblesHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
}
NSArray<IMHandle*> *handles = [[IMHandleRegistrar sharedInstance] getIMHandlesForID:(data[@"address"])];

if (handles != nil) {
if (handles == nil) {
if (transaction != nil) {
[[NetworkController sharedInstance] sendMessage: @{@"transactionId": transaction, @"error": @"Failed to load handles for provided address!"}];
}
Expand Down
9 changes: 8 additions & 1 deletion MacOS-11+/BlueBubblesHelper/NetworkController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ + (NetworkController*)sharedInstance {

#pragma mark - Public methods

#define CLAMP(x, low, high) ({\
__typeof__(x) __x = (x); \
__typeof__(low) __low = (low);\
__typeof__(high) __high = (high);\
__x > __high ? __high : (__x < __low ? __low : __x);\
})

- (void)connect {
// we need to get the port to open the server on (to allow multiple users to use the bundle)
// we'll base this off the users uid (a unique id for each user, starting from 501)
// we'll subtract 501 to get an id starting at 0, incremented for each user
// then we add this to the base port to get a unique port for the socket
int port = 45670 + getuid()-501;
int port = CLAMP(45670 + getuid()-501, 45670, 65535);
DLog(@"BLUEBUBBLESHELPER: Connecting to socket on port %d", port);
// connect to socket
asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
Expand Down

0 comments on commit 7d07f5c

Please sign in to comment.