-
Notifications
You must be signed in to change notification settings - Fork 59
Added RFC 3403-compliant guard clauses to DnsNAPTRRecordData constructor #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zbalkan
wants to merge
5
commits into
TechnitiumSoftware:master
Choose a base branch
from
zbalkan:fix/Add-RFC-3403-compliant-guard-clauses-to-DnsNAPTRRecordData-constructor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
98a3ba5
Added RFC 3403-compliant guard clauses to DnsNAPTRRecordData constructor
zbalkan 8bdc964
Added copyright
zbalkan 84661ed
Revert "Added copyright"
zbalkan 0d5a784
Removed the trailing dot check.
zbalkan 6dcaff3
Removed non-RFC-specified regex validation
zbalkan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -46,6 +46,64 @@ public class DnsNAPTRRecordData : DnsResourceRecordData | |
|
|
||
| public DnsNAPTRRecordData(ushort order, ushort preference, string flags, string services, string regexp, string replacement) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(flags); | ||
|
|
||
| ArgumentNullException.ThrowIfNull(services); | ||
|
|
||
| ArgumentNullException.ThrowIfNull(regexp); | ||
|
|
||
| ArgumentNullException.ThrowIfNull(replacement); | ||
|
|
||
| // RFC 3403: REGEXP and REPLACEMENT are mutually exclusive | ||
| // If both are present (non-empty), the record is in error and MUST be rejected or ignored. | ||
| if (regexp.Length > 0 && replacement.Length > 0) | ||
| throw new ArgumentException( | ||
| "REGEXP and REPLACEMENT are mutually exclusive per RFC 3403."); | ||
|
|
||
| // RFC 3403: FLAGS validation | ||
| // Flags are single characters from A–Z and 0–9, case-insensitive. | ||
| for (int i = 0; i < flags.Length; i++) | ||
| { | ||
| char c = flags[i]; | ||
| if (!(char.IsAsciiLetter(c) || char.IsAsciiDigit(c))) | ||
| throw new ArgumentException( | ||
| $"Invalid NAPTR flag '{c}'. Allowed set is A–Z and 0–9.", | ||
| nameof(flags)); | ||
| } | ||
|
|
||
| // RFC 3403: SERVICES is a DNS <character-string> | ||
| // RFC intentionally does NOT define semantics here; only basic sanity checks. | ||
| // Enforce non-control UTF-16 chars; deeper validation is application-specific. | ||
| for (int i = 0; i < services.Length; i++) | ||
| { | ||
| if (char.IsControl(services[i])) | ||
| throw new ArgumentException( | ||
| "SERVICES contains control characters, which are not permitted.", | ||
| nameof(services)); | ||
| } | ||
|
|
||
| // RFC 3403: REPLACEMENT must be a fully qualified domain name | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validation for REPLACEMENT is already in place done using |
||
| if (replacement.Length > 0) | ||
| { | ||
| // Must end with a root label (trailing dot) | ||
| // But zoneFile.PopDomainAsync() removes the trailing dot. | ||
| // Therefore the check is useless. | ||
|
|
||
| // No name compression, no empty labels except the root | ||
| if (replacement.Contains("..", StringComparison.Ordinal)) | ||
| throw new ArgumentException( | ||
| "REPLACEMENT contains empty DNS labels.", | ||
| nameof(replacement)); | ||
| } | ||
zbalkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // RFC 3403: REGEXP sanity | ||
| // The RFC requires POSIX ERE semantics but does not mandate compile-time validation. | ||
| // Enforce only that it is non-empty when used. | ||
| if (regexp.Length == 0 && replacement.Length == 0) | ||
| throw new ArgumentException( | ||
| "Either REGEXP or REPLACEMENT must be specified per RFC 3403."); | ||
|
|
||
| // DNS <character-string> constraints | ||
| if (DnsClient.IsDomainNameUnicode(replacement)) | ||
| replacement = DnsClient.ConvertDomainNameToAscii(replacement); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can contain arbitrary chars ans since the SERVICES parameter leaves it up to the application, validation for this param should be removed.