Bug 329715: investigate why some AV's flag us, and prevent it

patch: use rot13 on keys to avoid being flagged by avira antivirus
r=darin
This commit is contained in:
tony%ponderer.org 2006-09-05 18:54:11 +00:00
Родитель 2fb7d9553f
Коммит 86157bd887
1 изменённых файлов: 52 добавлений и 8 удалений

Просмотреть файл

@ -66,7 +66,8 @@ static const PRLogModuleInfo *gUrlClassifierDbServiceLog = nsnull;
#define LOG(args)
#endif
#define DATABASE_FILENAME "urlclassifier.sqlite"
// Change filename each time we change the db schema.
#define DATABASE_FILENAME "urlclassifier2.sqlite"
// Singleton instance.
static nsUrlClassifierDBService* sUrlClassifierDBService;
@ -76,6 +77,40 @@ static nsIThread* gDbBackgroundThread = nsnull;
static const char* kNEW_TABLE_SUFFIX = "_new";
// This maps A-M to N-Z and N-Z to A-M. All other characters are left alone.
// Copied from mailnews/mime/src/mimetext.cpp
static const unsigned char kRot13Table[256] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 91, 92, 93, 94, 95, 96,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 97, 98,
99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 123, 124, 125, 126,
127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246,
247, 248, 249, 250, 251, 252, 253, 254, 255 };
// Does an in place rotation of the line
static void
Rot13Line(nsCString &line)
{
nsCString::iterator start, end;
line.BeginWriting(start);
line.EndWriting(end);
while (start != end) {
*start = kRot13Table[*start];
++start;
}
}
// -------------------------------------------------------------------------
// Actual worker implemenatation
class nsUrlClassifierDBServiceWorker : public nsIUrlClassifierDBServiceWorker
@ -172,8 +207,6 @@ nsUrlClassifierDBServiceWorker::Exists(const nsACString& tableName,
const nsACString& key,
nsIUrlClassifierCallback *c)
{
LOG(("Exists\n"));
nsresult rv = OpenDb();
if (NS_FAILED(rv)) {
NS_ERROR("Unable to open database");
@ -196,7 +229,9 @@ nsUrlClassifierDBServiceWorker::Exists(const nsACString& tableName,
// If CreateStatment failed, this probably means the table doesn't exist.
// That's ok, we just return an emptry string.
if (NS_SUCCEEDED(rv)) {
rv = selectStatement->BindUTF8StringParameter(0, key);
nsCString keyROT13(key);
Rot13Line(keyROT13);
rv = selectStatement->BindUTF8StringParameter(0, keyROT13);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasMore = PR_FALSE;
@ -248,7 +283,7 @@ nsUrlClassifierDBServiceWorker::CheckTables(const nsACString & tableNames,
changedTables.Append(tableName);
}
}
c->HandleEvent(changedTables);
return NS_OK;
}
@ -535,22 +570,31 @@ nsUrlClassifierDBServiceWorker::ProcessUpdateTable(
// Insert operation of the form "+KEY\tVALUE"
const nsCSubstring &key = Substring(aLine, 1, spacePos - 1);
const nsCSubstring &value = Substring(aLine, spacePos + 1);
aUpdateStatement->BindUTF8StringParameter(0, key);
// We use ROT13 versions of keys to avoid antivirus utilities from
// flagging us as a virus.
nsCString keyROT13(key);
Rot13Line(keyROT13);
aUpdateStatement->BindUTF8StringParameter(0, keyROT13);
aUpdateStatement->BindUTF8StringParameter(1, value);
rv = aUpdateStatement->Execute();
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to update");
} else if ('-' == op) {
// Remove operation of the form "-KEY"
nsCString keyROT13;
if (spacePos == kNotFound) {
// No trailing tab
const nsCSubstring &key = Substring(aLine, 1);
aDeleteStatement->BindUTF8StringParameter(0, key);
keyROT13.Assign(key);
} else {
// With trailing tab
const nsCSubstring &key = Substring(aLine, 1, spacePos - 1);
aDeleteStatement->BindUTF8StringParameter(0, key);
keyROT13.Assign(key);
}
Rot13Line(keyROT13);
aDeleteStatement->BindUTF8StringParameter(0, keyROT13);
rv = aDeleteStatement->Execute();
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to delete");