-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NR-359870 fix for the attribute validator crash (#340)
* NR-359870 moved the attribute validator to utils so it can be static and used anywhere it's needed * moved the attribute validator to the BlockAttributeValidator class to try to address concerns. * Moved from the BlockAttributeValidator to an attribute validator that's it's own class * Changed it to pass the AttributeValidator in as a parameter to the handled exception, so it can be replaced for testing
- Loading branch information
Showing
12 changed files
with
166 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Agent/Analytics/AttributeValidator/NRMAAttributeValidator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// NRMAAttributeValidator.h | ||
// Agent | ||
// | ||
// Created by Mike Bruin on 1/24/25. | ||
// Copyright © 2025 New Relic. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "AttributeValidatorProtocol.h" | ||
|
||
@interface NRMAAttributeValidator : NSObject <AttributeValidatorProtocol> | ||
|
||
@end |
70 changes: 70 additions & 0 deletions
70
Agent/Analytics/AttributeValidator/NRMAAttributeValidator.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// NRMAAttributeValidator.m | ||
// Agent | ||
// | ||
// Created by Mike Bruin on 1/24/25. | ||
// Copyright © 2025 New Relic. All rights reserved. | ||
// | ||
|
||
#import "NRMAAttributeValidator.h" | ||
#import "Constants.h" | ||
#import "NRMAAnalytics.h" | ||
#import "NRLogger.h" | ||
|
||
@implementation NRMAAttributeValidator | ||
|
||
- (BOOL)eventTypeValidator:(NSString *)eventType { | ||
return YES; | ||
} | ||
|
||
- (BOOL)nameValidator:(NSString *)name { | ||
if ([name length] == 0) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: name length = 0"); | ||
return false; | ||
} | ||
if ([name hasPrefix:@" "]) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: name prefix = \" \""); | ||
return false; | ||
} | ||
// check if attribute name is reserved or attribute name matches reserved prefix. | ||
for (NSString* key in [NRMAAnalytics reservedKeywords]) { | ||
if ([key isEqualToString:name]) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: name prefix disallowed"); | ||
return false; | ||
} | ||
} | ||
for (NSString* key in [NRMAAnalytics reservedPrefixes]) { | ||
if ([name hasPrefix:key]) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: name prefix disallowed"); | ||
return false; | ||
} | ||
} | ||
|
||
// check if attribute name exceeds max length. | ||
if ([name length] > kNRMA_Attrib_Max_Name_Length) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: name length exceeds limit"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
- (BOOL)valueValidator:(id)value { | ||
if ([value isKindOfClass:[NSString class]]) { | ||
if ([(NSString*)value length] == 0) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: value length = 0"); | ||
return false; | ||
} | ||
else if ([(NSString*)value length] >= kNRMA_Attrib_Max_Value_Size_Bytes) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: value exceeded maximum byte size exceeded"); | ||
return false; | ||
} | ||
} | ||
if (value == nil || [value isKindOfClass:[NSNull class]]) { | ||
NRLOG_AGENT_ERROR(@"invalid attribute: value cannot be nil"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.