diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-04-14 17:59:40 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2024-04-14 17:59:40 -0500 |
| commit | 01a60e7f7eb25010dd35c1b3751906296d4e8733 (patch) | |
| tree | 36c1f09a796aaea38185f0c9aac52f3be1fce872 /src | |
| parent | 7767bde201c26349c3d465d775c9d895c01393ee (diff) | |
| download | slskd-01a60e7f7eb25010dd35c1b3751906296d4e8733.tar.gz | |
guard against malformed lines
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Core/Blacklist.cs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/slskd/Core/Blacklist.cs b/src/slskd/Core/Blacklist.cs index b91c9384..1f55e1ba 100644 --- a/src/slskd/Core/Blacklist.cs +++ b/src/slskd/Core/Blacklist.cs @@ -133,20 +133,27 @@ public class Blacklist note: we should never get this far without format being one of CIDR, P2P, DAT */ - // CIDR format: 1.2.4.0/24 - if (format == BlacklistFormat.CIDR && !IPAddressRange.TryParse(line, out cidr)) + try { - throw new FormatException($"Failed to parse blacklist line {lineNumber} '{line}' (expected {format} format)"); + // CIDR format: 1.2.4.0/24 + if (format == BlacklistFormat.CIDR && !IPAddressRange.TryParse(line, out cidr)) + { + throw new Exception(); + } + + // P2P format: China Internet Information Center (CNNIC):1.2.4.0-1.2.4.255 + else if (format == BlacklistFormat.P2P && !IPAddressRange.TryParse(line.Split(':')[1], out cidr)) + { + throw new Exception(); + } + + // DAT format: 001.002.004.000 - 001.002.004.255 , 000 , China Internet Information Center (CNNIC) + else if (format == BlacklistFormat.DAT && !IPAddressRange.TryParse(line.Split(",")[0], out cidr)) + { + throw new Exception(); + } } - - // P2P format: China Internet Information Center (CNNIC):1.2.4.0-1.2.4.255 - else if (format == BlacklistFormat.P2P && !IPAddressRange.TryParse(line.Split(':')[1], out cidr)) - { - throw new FormatException($"Failed to parse blacklist line {lineNumber} '{line}' (expected {format} format)"); - } - - // DAT format: 001.002.004.000 - 001.002.004.255 , 000 , China Internet Information Center (CNNIC) - else if (format == BlacklistFormat.DAT && !IPAddressRange.TryParse(line.Split(",")[0], out cidr)) + catch { throw new FormatException($"Failed to parse blacklist line {lineNumber} '{line}' (expected {format} format)"); } |
