Fix (mostly) UBSAN found issues 29/319129/1 accepted/tizen_unified_toolchain accepted/tizen/9.0/unified/20241030.234657 accepted/tizen/unified/20241016.160102 accepted/tizen/unified/toolchain/20241022.122433 accepted/tizen/unified/toolchain/20241022.122909 accepted/tizen/unified/x/20241017.030747 accepted/tizen/unified/x/asan/20241022.113447 tizen_9.0_m2_release
authorKrzysztof Malysa <k.malysa@samsung.com>
Tue, 15 Oct 2024 13:32:18 +0000 (15:32 +0200)
committerKrzysztof Malysa <k.malysa@samsung.com>
Tue, 15 Oct 2024 16:31:37 +0000 (18:31 +0200)
Change-Id: I25f714a654642c8c95bc02a881ec8543b913b9bd

tests/serialization-test.cpp
tests/utils-tests.cpp

index ecd4283d90d7b056909caf48880ad2fedba3d5e1..27ca36b11d6238acbac420a31a3a8aa048355d21 100644 (file)
@@ -20,8 +20,6 @@
  */
 #include <cstring>
 #include <gtest/gtest.h>
-#include <iostream>
-#include <string>
 #include <unistd.h>
 #include <message-buffer.h>
 #include <serialization.h>
@@ -392,19 +390,19 @@ TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_param_s_P)
 }
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_param_s_N1)
 {// serialize: invalid member
-    wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF),
+    wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0),
                                         WAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256};
     PubkeyCredParamSerializer data1(&param1);
     __testSerializeForInvalidMember(data1);
 
     wauthn_pubkey_cred_param_s param2 = {WAUTHN_PUBKEY_CRED_TYPE_PUBLIC_KEY,
-                                        static_cast<wauthn_cose_algorithm_e>(0x00FFFFFF)};
+                                        static_cast<wauthn_cose_algorithm_e>(0)};
     PubkeyCredParamSerializer data2(&param2);
     __testSerializeForInvalidMember(data2);
 }
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_param_s_N2)
 {// deserialize: for invalid type
-    wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF),
+    wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0),
                                             WAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256};
     __testDeserializeForInvalidMember<wauthn_pubkey_cred_param_s,
                                       PubkeyCredParamDeserializer>(param1);
@@ -504,7 +502,7 @@ TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_descriptor_s_P)
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_descriptor_s_N1)
 {// serialize: invalid member
     wauthn_pubkey_cred_descriptor_s data = TestCommonData::pubkeyCredDescriptor;
-    data.type = static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF);
+    data.type = static_cast<wauthn_pubkey_cred_type_e>(0);
     __testDeserializeForInvalidMember<wauthn_pubkey_cred_descriptor_s,
                                       PubkeyCredDescriptorDeserializer>(data);
 }
@@ -515,7 +513,7 @@ TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_descriptor_s_N2)
 }
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_descriptor_s_N3)
 {// deserialize: for invalid type
-    wauthn_pubkey_cred_descriptor_s data = {static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF),
+    wauthn_pubkey_cred_descriptor_s data = {static_cast<wauthn_pubkey_cred_type_e>(0),
                                             &TestCommonData::clientDataJson, 3};
     __testDeserializeForInvalidMember<wauthn_pubkey_cred_descriptor_s,
                                       PubkeyCredDescriptorDeserializer>(data);
@@ -700,23 +698,23 @@ TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_P)
 TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N1)
 {// serialize: invalid member
     wauthn_authenticator_sel_cri_s data1 = TestCommonData::authenticatorSelCri;
-    data1.attachment = static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF);
+    data1.attachment = static_cast<wauthn_authenticator_attachment_e>(3);
     __testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
                                       AuthenticatorSelCriDeserializer>(data1);
 
     wauthn_authenticator_sel_cri_s data2 = TestCommonData::authenticatorSelCri;
-    data2.resident_key = static_cast<wauthn_resident_key_requirement_e>(0x00FFFFFF);
+    data2.resident_key = static_cast<wauthn_resident_key_requirement_e>(4);
     __testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
                                       AuthenticatorSelCriDeserializer>(data2);
 
     wauthn_authenticator_sel_cri_s data3 = TestCommonData::authenticatorSelCri;
-    data3.user_verification = static_cast<wauthn_user_verification_requirement_e>(0x00FFFFFF);
+    data3.user_verification = static_cast<wauthn_user_verification_requirement_e>(4);
     __testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
                                       AuthenticatorSelCriDeserializer>(data3);
 }
 TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N2)
 {// deserialize: for invalid attachment
-    wauthn_authenticator_sel_cri_s data = {static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF),
+    wauthn_authenticator_sel_cri_s data = {static_cast<wauthn_authenticator_attachment_e>(3),
                                 WAUTHN_RESIDENT_KEY_REQUIREMENT_DISCOURAGED,
                                 false,
                                 WAUTHN_USER_VERIFICATION_REQUIREMENT_DISCOURAGED};
@@ -726,7 +724,7 @@ TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N2)
 TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N3)
 {// deserialize: for invalid resident_key
     wauthn_authenticator_sel_cri_s data = {WAUTHN_AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM,
-                                static_cast<wauthn_resident_key_requirement_e>(0x00FFFFFF),
+                                static_cast<wauthn_resident_key_requirement_e>(4),
                                 false,
                                 WAUTHN_USER_VERIFICATION_REQUIREMENT_DISCOURAGED};
     __testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
@@ -737,7 +735,7 @@ TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N4)
     wauthn_authenticator_sel_cri_s data = {WAUTHN_AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM,
                                 WAUTHN_RESIDENT_KEY_REQUIREMENT_DISCOURAGED,
                                 false,
-                                static_cast<wauthn_user_verification_requirement_e>(0x00FFFFFF)};
+                                static_cast<wauthn_user_verification_requirement_e>(4)};
     __testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
                                       AuthenticatorSelCriDeserializer>(data);
 }
@@ -975,7 +973,7 @@ TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_creation_options_s_N1)
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_creation_options_s_N2)
 {// serialize: invalid member
     wauthn_pubkey_cred_creation_options_s data = TestCommonData::pubkeyCredCreationOptions;
-    data.attestation = static_cast<wauthn_attestation_pref_e>(0x00FFFFFF);
+    data.attestation = static_cast<wauthn_attestation_pref_e>(4);
     __testDeserializeForInvalidMember<wauthn_pubkey_cred_creation_options_s,
                                       PubKeyCredCreationOptionsDeserializer>(data);
 }
@@ -1029,14 +1027,14 @@ TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_request_options_s_P)
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_request_options_s_N1)
 {// serialize: invalid member
     wauthn_pubkey_cred_request_options_s data = TestCommonData::pubkeyCredRequestOptions;
-    data.user_verification = static_cast<wauthn_user_verification_requirement_e>(0x00FFFFFF);
+    data.user_verification = static_cast<wauthn_user_verification_requirement_e>(4);
     __testDeserializeForInvalidMember<wauthn_pubkey_cred_request_options_s,
                                       PubKeyCredRequestOptionsDeserializer>(data);
 }
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_request_options_s_N2)
 {// serialize: invalid member
     wauthn_pubkey_cred_request_options_s data = TestCommonData::pubkeyCredRequestOptions;
-    data.attestation = static_cast<wauthn_attestation_pref_e>(0x00FFFFFF);
+    data.attestation = static_cast<wauthn_attestation_pref_e>(4);
     __testDeserializeForInvalidMember<wauthn_pubkey_cred_request_options_s,
                                       PubKeyCredRequestOptionsDeserializer>(data);
 }
@@ -1096,14 +1094,14 @@ TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_attestation_s_N1)
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_attestation_s_N2)
 {// deserialize: for invalid type
     wauthn_pubkey_credential_attestation_s data = TestCommonData::pubkeyCredentialAttestation;
-    data.type = static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF);
+    data.type = static_cast<wauthn_pubkey_cred_type_e>(0);
     __testDeserializeForInvalidMember<wauthn_pubkey_credential_attestation_s,
                                       PubkeyCredentialAttestationDeserializer>(data);
 }
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_attestation_s_N3)
 {// deserialize: for invalid authenticator_attachment
     wauthn_pubkey_credential_attestation_s data = TestCommonData::pubkeyCredentialAttestation;
-    data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF);
+    data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(3);
     __testDeserializeForInvalidMember<wauthn_pubkey_credential_attestation_s,
                                       PubkeyCredentialAttestationDeserializer>(data);
 }
@@ -1158,14 +1156,14 @@ TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_assertion_s_N1)
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_assertion_s_N2)
 {// deserialize: for invalid type
     wauthn_pubkey_credential_assertion_s data = TestCommonData::pubkeyCredentialAssertion;
-    data.type = static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF);
+    data.type = static_cast<wauthn_pubkey_cred_type_e>(0);
     __testDeserializeForInvalidMember<wauthn_pubkey_credential_assertion_s,
                                       PubkeyCredentialAssertionDeserializer>(data);
 }
 TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_assertion_s_N3)
 {// deserialize: for invalid authenticator_attachment
     wauthn_pubkey_credential_assertion_s data = TestCommonData::pubkeyCredentialAssertion;
-    data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF);
+    data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(3);
     __testDeserializeForInvalidMember<wauthn_pubkey_credential_assertion_s,
                                       PubkeyCredentialAssertionDeserializer>(data);
 }
@@ -1203,7 +1201,7 @@ TEST_F(WAuthnSerializationTest, wauthn_client_data_s_P)
 TEST_F(WAuthnSerializationTest, wauthn_client_data_s_N1)
 {// serialize: invalid member
     wauthn_client_data_s data = TestCommonData::clientData;
-    data.hash_alg = static_cast<wauthn_hash_algorithm_e>(0x00FFFFFF);
+    data.hash_alg = static_cast<wauthn_hash_algorithm_e>(0);
     __testDeserializeForInvalidMember<wauthn_client_data_s, ClientDataDeserializer>(data);
 }
 TEST_F(WAuthnSerializationTest, wauthn_client_data_s_N2)
index 36050e96d714a7aafa6e609c6047ff7a5e23772c..048714f386ed65e2c1c6c9db2764e92d99d2c16e 100644 (file)
@@ -194,7 +194,7 @@ TEST_F(UtilsTest, check_parameter_clientdata_invalid_hash_N)
 {
     auto clientData = TestCommonData::clientData;
     auto backupData = clientData.hash_alg;
-    clientData.hash_alg = (wauthn_hash_algorithm_e)-1;
+    clientData.hash_alg = static_cast<wauthn_hash_algorithm_e>(0);
     int ret = try_catch([&]() -> int {
         CheckParameters(&clientData);
         return WAUTHN_ERROR_NONE;
@@ -329,7 +329,7 @@ TEST_F(UtilsTest, check_parameter_options_pubkey_cred_params_ignore_invalid_type
     {
         int ret = WAUTHN_ERROR_NONE;
         auto backupData = credParams.params[i].type;
-        credParams.params[i].type = (wauthn_pubkey_cred_type_e)-1;
+        credParams.params[i].type = static_cast<wauthn_pubkey_cred_type_e>(0);
         ret = try_catch([&]() -> int {
             CheckParameters(&credParams);
             return WAUTHN_ERROR_NONE;
@@ -346,7 +346,7 @@ TEST_F(UtilsTest, check_parameter_options_pubkey_cred_params_invalid_alg_N)
     {
         int ret = WAUTHN_ERROR_NONE;
         auto backupData = credParams.params[i].alg;
-        credParams.params[i].alg = (wauthn_cose_algorithm_e)-1;
+        credParams.params[i].alg = static_cast<wauthn_cose_algorithm_e>(0);
         ret = try_catch([&]() -> int {
             CheckParameters(&credParams);
             return WAUTHN_ERROR_NONE;
@@ -389,7 +389,7 @@ TEST_F(UtilsTest, check_parameter_options_cred_descriptors_ignore_invalid_type_P
     {
         int ret = WAUTHN_ERROR_NONE;
         auto backupData = credDescs.descriptors[i].type;
-        credDescs.descriptors[i].type = (wauthn_pubkey_cred_type_e)-1;
+        credDescs.descriptors[i].type = static_cast<wauthn_pubkey_cred_type_e>(0);
         ret = try_catch([&]() -> int {
             CheckParameters(&credDescs);
             return WAUTHN_ERROR_NONE;
@@ -455,7 +455,7 @@ TEST_F(UtilsTest, check_parameter_options_authenticator_selection_ignore_invalid
 {
     auto authSel = TestCommonData::authenticatorSelCri;
     auto backupData = authSel.attachment;
-    authSel.attachment = (wauthn_authenticator_attachment_e)-1;
+    authSel.attachment = static_cast<wauthn_authenticator_attachment_e>(3);
     int ret = try_catch([&]() -> int {
         CheckParameters(&authSel);
         return WAUTHN_ERROR_NONE;
@@ -468,7 +468,7 @@ TEST_F(UtilsTest, check_parameter_options_authenticator_selection_ignore_invalid
 {
     auto authSel = TestCommonData::authenticatorSelCri;
     auto backupData = authSel.resident_key;
-    authSel.resident_key = (wauthn_resident_key_requirement_e)-1;
+    authSel.resident_key = static_cast<wauthn_resident_key_requirement_e>(4);
     int ret = try_catch([&]() -> int {
         CheckParameters(&authSel);
         return WAUTHN_ERROR_NONE;
@@ -481,7 +481,7 @@ TEST_F(UtilsTest, check_parameter_options_authenticator_selection_ignore_invalid
 {
     auto authSel = TestCommonData::authenticatorSelCri;
     auto backupData = authSel.user_verification;
-    authSel.user_verification = (wauthn_user_verification_requirement_e)-1;
+    authSel.user_verification = static_cast<wauthn_user_verification_requirement_e>(4);
     int ret = try_catch([&]() -> int {
         CheckParameters(&authSel);
         return WAUTHN_ERROR_NONE;
@@ -539,7 +539,7 @@ TEST_F(UtilsTest, check_parameter_options_hints_invalid_value_P)
     {
         int ret = WAUTHN_ERROR_NONE;
         auto backupData = hints.hints[i];
-        hints.hints[i] = (wauthn_pubkey_cred_hint_e)-1;
+        hints.hints[i] = static_cast<wauthn_pubkey_cred_hint_e>(4);
         ret = try_catch([&]() -> int {
             CheckParameters(&hints);
             return WAUTHN_ERROR_NONE;
@@ -1037,7 +1037,7 @@ TEST_F(UtilsTest, check_parameter_MC_options_ignore_invalid_attestation_P)
 {
     auto options = TestCommonData::pubkeyCredCreationOptions;
     auto backupData = options.attestation;
-    options.attestation = (wauthn_attestation_pref_e)-1;
+    options.attestation = static_cast<wauthn_attestation_pref_e>(4);
     int ret = try_catch([&]() -> int {
         CheckParameters(&options);
         return WAUTHN_ERROR_NONE;