Skip to content

Commit 114c2df

Browse files
committed
Added guard clauses for secret file loading
1 parent 3f84da7 commit 114c2df

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

DnsServerCore/Dns/Security/DnsCookieSecretManager.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,24 @@ private void Load()
6666
if (version == 1)
6767
{
6868
_currentSecretCreated = new DateTime(br.ReadInt64(), DateTimeKind.Utc);
69-
70-
int currentLen = br.ReadInt32();
69+
70+
int currentLen = br.ReadInt32(); // TODO: Validate length if between 8 and 256 bytes
71+
if (currentLen < 8 || currentLen > 256)
72+
throw new InvalidDataException("Invalid current secret length.");
73+
7174
_currentSecret = br.ReadBytes(currentLen);
7275

7376
int previousLen = br.ReadInt32();
77+
if (previousLen < 0 || previousLen > 256)
78+
throw new InvalidDataException("Invalid previous secret length.");
79+
7480
if (previousLen > 0)
7581
_previousSecret = br.ReadBytes(previousLen);
7682
}
83+
else
84+
{
85+
throw new InvalidDataException("Unsupported secret file version.");
86+
}
7787
}
7888
}
7989
catch

0 commit comments

Comments
 (0)