Skip to content

Commit

Permalink
Fix issue with invalid lengths (#1122)
Browse files Browse the repository at this point in the history
* Fix issue with invalid lengths

* Disable clang format around a small block of code for now
  • Loading branch information
mlw authored Jul 6, 2023
1 parent dde42ee commit cd719cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Source/common/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
// Pretty print C++ string match errors
#define XCTAssertCppStringEqual(got, want) XCTAssertCStringEqual((got).c_str(), (want).c_str())

// Note: Delta between local formatter and the one run on Github. Disable for now.
// clang-format off
#define XCTAssertSemaTrue(s, sec, m) \
XCTAssertEqual( \
0, dispatch_semaphore_wait((s), dispatch_time(DISPATCH_TIME_NOW, (sec)*NSEC_PER_SEC)), m)
0, dispatch_semaphore_wait((s), dispatch_time(DISPATCH_TIME_NOW, (sec) * NSEC_PER_SEC)), m)
// clang-format on

// Helper to ensure at least `ms` milliseconds are slept, even if the sleep
// function returns early due to interrupts.
Expand Down
1 change: 1 addition & 0 deletions Source/santad/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ objc_library(
"//Source/common:PrefixTree",
"//Source/common:SNTConfigurator",
"//Source/common:SNTLogging",
"//Source/common:String",
"//Source/common:Unit",
],
)
Expand Down
10 changes: 7 additions & 3 deletions Source/santad/EventProviders/SNTEndpointSecurityRecorder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#import "Source/common/SNTConfigurator.h"
#import "Source/common/SNTLogging.h"
#include "Source/common/String.h"
#include "Source/santad/EventProviders/AuthResultCache.h"
#include "Source/santad/EventProviders/EndpointSecurity/EnrichedTypes.h"
#include "Source/santad/EventProviders/EndpointSecurity/Message.h"
Expand Down Expand Up @@ -86,7 +87,7 @@ - (void)handleMessage:(Message &&)esMsg
recordEventMetrics:(void (^)(EventDisposition))recordEventMetrics {
// Pre-enrichment processing
switch (esMsg->event_type) {
case ES_EVENT_TYPE_NOTIFY_CLOSE:
case ES_EVENT_TYPE_NOTIFY_CLOSE: {
// TODO(mlw): Once we move to building with the macOS 13 SDK, we should also check
// the `was_mapped_writable` field
if (esMsg->event.close.modified == false) {
Expand All @@ -100,10 +101,11 @@ - (void)handleMessage:(Message &&)esMsg
self->_authResultCache->RemoveFromCache(esMsg->event.close.target);

// Only log file changes that match the given regex
NSString *targetPath = santa::common::StringToNSString(esMsg->event.close.target->path.data);
if (![[self.configurator fileChangesRegex]
numberOfMatchesInString:@(esMsg->event.close.target->path.data)
numberOfMatchesInString:targetPath
options:0
range:NSMakeRange(0, esMsg->event.close.target->path.length)]) {
range:NSMakeRange(0, targetPath.length)]) {
// Note: Do not record metrics in this case. These are not considered "drops"
// because this is not a failure case.
// TODO(mlw): Consider changes to configuration that would allow muting paths
Expand All @@ -112,6 +114,8 @@ - (void)handleMessage:(Message &&)esMsg
}

break;
}

default: break;
}

Expand Down

0 comments on commit cd719cc

Please sign in to comment.