Skip to content

Commit 771aa42

Browse files
committed
Merge branch 'hotfix/SDK-4965_repair_corrupt_jscd_user_attribute' into 'release/v9.0.0'
SDK-4965. Repair corrupt "jscd" user's attribute (hotfix for v9.0.0) See merge request sdk/sdk!6396
2 parents dbf2c61 + f88d404 commit 771aa42

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

examples/megacli.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ void DemoApp::getua_result(unique_ptr<string_map> records, attr_t type)
14071407
{
14081408
if (!records)
14091409
{
1410-
cout << "Error getting private user attribute" << endl;
1410+
cout << "Error getting private user attribute: No valid records in the attribute" << endl;
14111411
}
14121412
else if (!gVerboseMode)
14131413
{

include/mega/types.h

+1
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ typedef enum {
876876
REASON_ERROR_DB_FULL = 3,
877877
REASON_ERROR_DB_INDEX_OVERFLOW = 4,
878878
REASON_ERROR_NO_JSCD = 5,
879+
REASON_ERROR_REGENERATE_JSCD = 6,
879880
} ErrorReason;
880881

881882
//#define MEGA_MEASURE_CODE // uncomment this to track time spent in major subsystems, and log it every 2 minutes, with extra control from megacli

include/megaapi.h

+2
Original file line numberDiff line numberDiff line change
@@ -5857,6 +5857,7 @@ class MegaEvent
58575857
REASON_ERROR_DB_FULL = 3, // Failure at DB layer because disk is full
58585858
REASON_ERROR_DB_INDEX_OVERFLOW = 4, // Index used to primary key at db overflow
58595859
REASON_ERROR_NO_JSCD = 5, // No JSON Sync Config Data
5860+
REASON_ERROR_REGENERATE_JSCD = 6, // JSON Sync Config Data has been regenerated
58605861
};
58615862

58625863
virtual ~MegaEvent();
@@ -5906,6 +5907,7 @@ class MegaEvent
59065907
* - REASON_ERROR_DB_FULL = 3 -> Failure at DB layer because disk is full
59075908
* - REASON_ERROR_DB_INDEX_OVERFLOW = 4 -> Index used to primary key at db overflow
59085909
* - REASON_ERROR_NO_JSCD = 5 -> No JSON Sync Config Data
5910+
* - REASON_ERROR_REGENERATE_JSCD = 6 -> JSON Sync Config Data has been regenerated
59095911
*
59105912
* @return Number relative to this event
59115913
*/

src/commands.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -3778,10 +3778,19 @@ bool CommandGetUA::procresult(Result r, JSON& json)
37783778
{
37793779
LOG_err << "Cannot extract TLV records for private attribute "
37803780
<< User::attr2string(at);
3781-
mCompletionErr(API_EINTERNAL);
3781+
if (at == ATTR_JSON_SYNC_CONFIG_DATA)
3782+
{
3783+
// Store the attribute so we can update it later with valid
3784+
// values
3785+
u->setAttribute(at, value, version);
3786+
mCompletionErr(API_EKEY);
3787+
}
3788+
else
3789+
{
3790+
mCompletionErr(API_EINTERNAL);
3791+
}
37823792
return true;
37833793
}
3784-
37853794
break;
37863795
}
37873796
case ATTR_SCOPE_PUBLIC_UNENCRYPTED:
@@ -4237,7 +4246,7 @@ bool CommandGetUserData::updatePrivateEncryptedUserAttribute(User* u,
42374246
}
42384247
else
42394248
{
4240-
LOG_err << "Cannot extract TLV records for " << at;
4249+
LOG_err << "Cannot extract TLV records for " << User::attr2string(at);
42414250
}
42424251
}
42434252
else

src/megaclient.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -15279,10 +15279,11 @@ void MegaClient::fatalError(ErrorReason errorReason)
1527915279
mLastErrorDetected = errorReason;
1528015280

1528115281
// Disable sync.
15282-
// Sync is not enabled in case of ErrorReason::REASON_ERROR_NO_JSCD,
15283-
// therefore no need to disable it.
15282+
// Sync is not enabled in case of ErrorReason::REASON_ERROR_NO_JSCD or
15283+
// ErrorReason::REASON_ERROR_REGENERATE_JSCD therefore no need to disable it.
1528415284
#ifdef ENABLE_SYNC
15285-
if (errorReason != ErrorReason::REASON_ERROR_NO_JSCD)
15285+
if (errorReason != ErrorReason::REASON_ERROR_NO_JSCD &&
15286+
errorReason != ErrorReason::REASON_ERROR_REGENERATE_JSCD)
1528615287
{
1528715288
syncs.disableSyncs(FAILURE_ACCESSING_PERSISTENT_STORAGE, false, true);
1528815289
}
@@ -15312,6 +15313,10 @@ void MegaClient::fatalError(ErrorReason errorReason)
1531215313
reason = "Failed to get JSON SYNC configuration data";
1531315314
sendevent(99488, reason.c_str(), 0);
1531415315
break;
15316+
case ErrorReason::REASON_ERROR_REGENERATE_JSCD:
15317+
reason = "Fix JSON SYNC configuration data";
15318+
sendevent(99489, reason.c_str(), 0);
15319+
break;
1531515320
case ErrorReason::REASON_ERROR_UNKNOWN:
1531615321
reason = "Unknown fatal error";
1531715322
sendevent(99489, reason.c_str(), 0);
@@ -23867,9 +23872,17 @@ void MegaClient::JSCDataRetrieved(GetJSCDataCallback& callback,
2386723872
// Sanity.
2386823873
assert(callback);
2386923874

23870-
// The user doesn't have any JSC data.
23871-
if (result == API_ENOENT)
23875+
// The user doesn't have any JSC data or the attribute can't be decrypted or the attribute
23876+
// exists but is fully empty. In any case, create a new one.
23877+
if (result == API_ENOENT || result == API_EKEY || (result == API_OK && !store))
2387223878
{
23879+
if (result != API_ENOENT)
23880+
{
23881+
LOG_err << "Couldn't extract JSON SYNC configuration data. Automatically regenerating "
23882+
"the attribute";
23883+
// Send an event and notify the app. Existing syncs (if any) have been removed.
23884+
fatalError(ErrorReason::REASON_ERROR_REGENERATE_JSCD);
23885+
}
2387323886
return createJSCData(std::move(callback));
2387423887
}
2387523888

0 commit comments

Comments
 (0)