[dataset] shrink SecurityPolicyTlv and increase ActiveTimestamp

This commit added a hotfix to shrink SecurityPolicyTlv and increase
ActiveTimestamp by 1 second if the security policy is longer than
expected during restoring the dataset from local storage.

Bug: b/230050568
Test: create network in 1.2 mode and start again with 1.1 mode.
Verify the dataset is shrinked and the timestamp is increased.
restart in 1.1 mode
Verify the changes are persisted.
Verify MTD still attached to the leader.

Change-Id: I43ba5884bd34f4e81eb461c36bcbbfb15bec8684
diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp
index d241b1f..ac56fa2 100644
--- a/src/core/meshcop/dataset_manager.cpp
+++ b/src/core/meshcop/dataset_manager.cpp
@@ -83,6 +83,20 @@
 
     if (IsActiveDataset())
     {
+#if OPENTHREAD_CONFIG_THREAD_VERSION == OT_THREAD_VERSION_1_1 && OPENTHREAD_FTD
+        SecurityPolicyTlv securityPolicyTlv = *dataset.GetTlv<SecurityPolicyTlv>();
+
+        if (securityPolicyTlv.GetLength() > sizeof(securityPolicyTlv) - sizeof(Tlv))
+        {
+            securityPolicyTlv.SetLength(sizeof(securityPolicyTlv) - sizeof(Tlv));
+            SuccessOrExit(error = dataset.SetTlv(securityPolicyTlv));
+
+            mTimestamp.SetSeconds(mTimestamp.GetSeconds() + 1);
+
+            dataset.SetTimestamp(mTimestamp);
+            SuccessOrExit(error = mLocal.Save(dataset));
+        }
+#endif
         IgnoreError(dataset.ApplyConfiguration(GetInstance()));
     }