Skip to content

Commit 2aa56ad

Browse files
authored
Add bounds check for header substring operation
Added bounds check before substring operation to prevent ArgumentOutOfRangeException.
1 parent a1719f7 commit 2aa56ad

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

nanoFramework.System.Net.Http/Http/System.Net.WebHeaders.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,16 @@ public void Add(string header)
427427
}
428428

429429
string name = header.Substring(0, colpos);
430-
string value = header.Substring(colpos + 1);
430+
// Fix: Check bounds before Substring to prevent ArgumentOutOfRangeException
431+
string value;
432+
if (colpos + 1 >= header.Length)
433+
{
434+
value = string.Empty;
435+
}
436+
else
437+
{
438+
value = header.Substring(colpos + 1);
439+
}
431440

432441
name = CheckBadChars(name, false);
433442
ThrowOnRestrictedHeader(name);

0 commit comments

Comments
 (0)