diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-28 23:10:50 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-28 23:10:50 +0300 |
commit | 098d46fbf4a61d2be79817f05fedc55801d7aa68 (patch) | |
tree | b96c551c522d7bab41330b89ecd5c6ffc77e67f4 | |
parent | dcd16671be887922a68edc4e5020fdc8fe4a6dd1 (diff) |
fix for losing info due to MDBX_RESERVE flag
-rw-r--r-- | plugins/Dbx_mdbx/src/dbcrypt.cpp | 9 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbevents.cpp | 28 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/dbsettings.cpp | 50 |
3 files changed, 48 insertions, 39 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 31c2a24b76..0a6585e565 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -201,10 +201,9 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) dwNewFlags = dbEvent->flags | DBEF_ENCRYPTED;
}
- txn_ptr trnlck(StartTran());
data.iov_len = sizeof(DBEvent) + nNewBlob;
- if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
- return 1;
+ mir_ptr<BYTE> pData((BYTE*)mir_alloc(data.iov_len));
+ data.iov_base = pData.get();
DBEvent *pNewDBEvent = (DBEvent *)data.iov_base;
*pNewDBEvent = *dbEvent;
@@ -212,6 +211,10 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) pNewDBEvent->flags = dwNewFlags;
memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob);
+ txn_ptr trnlck(StartTran());
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
+ return 1;
+
if (trnlck.commit() != MDBX_SUCCESS)
return 1;
}
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp index 572c193475..4ad32afe54 100644 --- a/plugins/Dbx_mdbx/src/dbevents.cpp +++ b/plugins/Dbx_mdbx/src/dbevents.cpp @@ -87,16 +87,16 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) MEVENT dwEventId = InterlockedIncrement(&m_dwMaxEventId);
{
- txn_ptr trnlck(StartTran());
-
- MDBX_val key = { &dwEventId, sizeof(MEVENT) }, data = { nullptr, sizeof(DBEvent) + dbe.cbBlob };
- if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
- return 0;
-
- DBEvent *pNewEvent = (DBEvent*)data.iov_base;
+ BYTE *recBuf = (BYTE*)_alloca(sizeof(DBEvent) + dbe.cbBlob);
+ DBEvent *pNewEvent = (DBEvent*)recBuf;
*pNewEvent = dbe;
memcpy(pNewEvent + 1, pBlob, dbe.cbBlob);
+ txn_ptr trnlck(StartTran());
+ MDBX_val key = { &dwEventId, sizeof(MEVENT) }, data = { recBuf, sizeof(DBEvent) + dbe.cbBlob };
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
+ return 0;
+
// add a sorting key
DBEventSortingKey key2 = { contactID, dwEventId, dbe.timestamp };
key.iov_len = sizeof(key2); key.iov_base = &key2;
@@ -106,7 +106,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei) cc->Advance(dwEventId, dbe);
if (contactID != 0) {
- MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
+ MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
return 0;
@@ -319,15 +319,17 @@ STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent) if (cdbe->markedRead())
return cdbe->flags;
- DBEventSortingKey keyVal = { contactID, hDbEvent, cdbe->timestamp };
- if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
- return -1;
+ void *recBuf = _alloca(data.iov_len);
+ memcpy(recBuf, data.iov_base, data.iov_len);
+ data.iov_base = recBuf;
DBEvent *pNewEvent = (DBEvent*)data.iov_base;
- *pNewEvent = *cdbe;
-
wRetVal = (pNewEvent->flags |= DBEF_READ);
+ DBEventSortingKey keyVal = { contactID, hDbEvent, cdbe->timestamp };
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
+ return -1;
+
FindNextUnread(trnlck, cc, keyVal);
key.iov_len = sizeof(MCONTACT); key.iov_base = &contactID;
data.iov_base = &cc->dbc; data.iov_len = sizeof(cc->dbc);
diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp index 31f326df78..e8294b4b72 100644 --- a/plugins/Dbx_mdbx/src/dbsettings.cpp +++ b/plugins/Dbx_mdbx/src/dbsettings.cpp @@ -295,7 +295,6 @@ LBL_WriteString: keyVal->dwModuleId = GetModuleID(dbcws->szModule);
memcpy(&keyVal->szSettingName, dbcws->szSetting, settingNameLen + 1);
-
MDBX_val key = { keyVal, sizeof(DBSettingKey) + settingNameLen }, data;
switch (dbcwWork.value.type) {
@@ -310,34 +309,39 @@ LBL_WriteString: case DBVT_BLOB:
case DBVT_ENCRYPTED:
data.iov_len = 3 + dbcwWork.value.cpbVal; break;
+
+ default:
+ return 1;
+ }
+
+ data.iov_base = _alloca(data.iov_len);
+
+ BYTE *pBlob = (BYTE*)data.iov_base;
+ *pBlob++ = dbcwWork.value.type;
+ switch (dbcwWork.value.type) {
+ case DBVT_BYTE: *pBlob = dbcwWork.value.bVal; break;
+ case DBVT_WORD: *(WORD*)pBlob = dbcwWork.value.wVal; break;
+ case DBVT_DWORD: *(DWORD*)pBlob = dbcwWork.value.dVal; break;
+
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ *(WORD*)pBlob = dbcwWork.value.cchVal;
+ pBlob += 2;
+ memcpy(pBlob, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
+ break;
+
+ case DBVT_BLOB:
+ case DBVT_ENCRYPTED:
+ *(WORD*)pBlob = dbcwWork.value.cpbVal;
+ pBlob += 2;
+ memcpy(pBlob, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
}
{
txn_ptr trnlck(StartTran());
- if (mdbx_put(trnlck, m_dbSettings, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
+ if (mdbx_put(trnlck, m_dbSettings, &key, &data, 0) != MDBX_SUCCESS)
return 1;
- BYTE *pBlob = (BYTE*)data.iov_base;
- *pBlob++ = dbcwWork.value.type;
- switch (dbcwWork.value.type) {
- case DBVT_BYTE: *pBlob = dbcwWork.value.bVal; break;
- case DBVT_WORD: *(WORD*)pBlob = dbcwWork.value.wVal; break;
- case DBVT_DWORD: *(DWORD*)pBlob = dbcwWork.value.dVal; break;
-
- case DBVT_ASCIIZ:
- case DBVT_UTF8:
- data.iov_len = *(WORD*)pBlob = dbcwWork.value.cchVal;
- pBlob += 2;
- memcpy(pBlob, dbcwWork.value.pszVal, dbcwWork.value.cchVal);
- break;
-
- case DBVT_BLOB:
- case DBVT_ENCRYPTED:
- data.iov_len = *(WORD*)pBlob = dbcwWork.value.cpbVal;
- pBlob += 2;
- memcpy(pBlob, dbcwWork.value.pbVal, dbcwWork.value.cpbVal);
- }
-
if (trnlck.commit() != MDBX_SUCCESS)
return 1;
}
|