mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
- Made ipfilter.dat parser less sensitive to errors
This commit is contained in:
parent
86cfe82b89
commit
98ecb97790
1 changed files with 45 additions and 41 deletions
|
@ -790,15 +790,20 @@ void options_imp::processFilterFile(const QString& filePath){
|
||||||
while (!file.atEnd()) {
|
while (!file.atEnd()) {
|
||||||
++nbLine;
|
++nbLine;
|
||||||
QByteArray line = file.readLine();
|
QByteArray line = file.readLine();
|
||||||
if(!line.startsWith('#') && !line.startsWith("//")){
|
if(line.startsWith('#') || line.startsWith("//")) continue;
|
||||||
// Line is not commented
|
// Line is not commented
|
||||||
QList<QByteArray> partsList = line.split(',');
|
QList<QByteArray> partsList = line.split(',');
|
||||||
unsigned int nbElem = partsList.size();
|
unsigned int nbElem = partsList.size();
|
||||||
if(nbElem < 2){
|
if(nbElem < 2){
|
||||||
std::cerr << "Ipfilter.dat: line " << nbLine << " is malformed.\n";
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bool ok;
|
||||||
|
int nbAccess = partsList.at(1).trimmed().toInt(&ok);
|
||||||
|
if(!ok){
|
||||||
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int nbAccess = partsList.at(1).trimmed().toInt();
|
|
||||||
if(nbAccess <= 127){
|
if(nbAccess <= 127){
|
||||||
QString strComment;
|
QString strComment;
|
||||||
QString strStartIP = partsList.at(0).split('-').at(0).trimmed();
|
QString strStartIP = partsList.at(0).split('-').at(0).trimmed();
|
||||||
|
@ -811,13 +816,13 @@ void options_imp::processFilterFile(const QString& filePath){
|
||||||
// Split IP
|
// Split IP
|
||||||
IP = strStartIP.split('.');
|
IP = strStartIP.split('.');
|
||||||
if(IP.size() != 4){
|
if(IP.size() != 4){
|
||||||
std::cerr << "Ipfilter.dat: line " << nbLine << ", first IP is malformed.\n";
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
||||||
IP = strEndIP.split('.');
|
IP = strEndIP.split('.');
|
||||||
if(IP.size() != 4){
|
if(IP.size() != 4){
|
||||||
std::cerr << "Ipfilter.dat: line " << nbLine << ", second IP is malformed.\n";
|
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
|
||||||
|
@ -835,7 +840,6 @@ void options_imp::processFilterFile(const QString& filePath){
|
||||||
filter.add_rule(start, last, ip_filter::blocked);
|
filter.add_rule(start, last, ip_filter::blocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue