- priority: 5 --> 9
C# API for GeoIP contains error in file
LookupService.cs on line 524, where is following for
cycle:
for (int i = 0;i < MAX_ORG_RECORD_LENGTH;i++) {
buf[i] = dbbuffer[i+record_pointer];
}
When searching ISP, e. g. with IP 24.106.0.0, and use
LookupService with option GEOIP_MEMORY_CACHE, we get
System.IndexOutOfRangeException. This is caused by
access to array dbbuffer at index which is larger than
array size. Block of code with error look like this:
if ((dboptions & GEOIP_MEMORY_CACHE) == 1) {
for (int i = 0;i < MAX_ORG_RECORD_LENGTH;i++) {
buf[i] = dbbuffer[i+record_pointer];
}
}
We can fix this bug recoding this code, to look like
this block:
if ((dboptions & GEOIP_MEMORY_CACHE) == 1) {
int buffer_length = MAX_ORG_RECORD_LENGTH;
if (record_pointer + buffer_length - 1 >=
dbbuffer.Length) buffer_length = dbbuffer.Length -
record_pointer;
for (int i = 0; i < buffer_length; i++)
{
buf[i] = dbbuffer[i+record_pointer];
}
}