bios_table: Check the attr type when set attr value

When setting an attribute, we only checked whether
the attributes's type is non-read-only, but the remote
may send a non-read-only type that does not match the
attribute.

eg, set an integer attribute:

the remote should send:
1(attr handle), 0x03(attr type,integer, non-read-only),100(integer value)

but it may send:
1(attr handle), 0x01(attr type,string, non-read-only),100(integer value)
which is wrong.

Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I7db8b65f39b40624202627e2b4f94088dee0b423
diff --git a/libpldm/bios_table.c b/libpldm/bios_table.c
index 2f8d7f1..8c04f36 100644
--- a/libpldm/bios_table.c
+++ b/libpldm/bios_table.c
@@ -1059,7 +1059,7 @@
 	    src_table, src_length, PLDM_BIOS_ATTR_VAL_TABLE);
 
 	int rc = PLDM_SUCCESS;
-	const struct pldm_bios_attr_val_table_entry *tmp;
+	const struct pldm_bios_attr_val_table_entry *tmp, *to_update = entry;
 	size_t buffer_length = *dest_length, copied_length = 0, length = 0;
 	while (!pldm_bios_table_iter_is_end(iter)) {
 		tmp = pldm_bios_table_iter_attr_value_entry_value(iter);
@@ -1069,9 +1069,11 @@
 		 * it too, use current_pos directly to avoid calculating it
 		 * twice */
 		iter->current_pos += length;
-		if (tmp->attr_handle ==
-		    ((const struct pldm_bios_attr_val_table_entry *)entry)
-			->attr_handle) {
+		if (tmp->attr_handle == to_update->attr_handle) {
+			if (tmp->attr_type != to_update->attr_type) {
+				rc = PLDM_ERROR_INVALID_DATA;
+				goto out;
+			}
 			if (attribute_is_readonly(tmp->attr_type)) {
 				rc = PLDM_ERROR_INVALID_DATA;
 				goto out;
diff --git a/test/libpldm_bios_table_test.cpp b/test/libpldm_bios_table_test.cpp
index 283425d..b4a6022 100644
--- a/test/libpldm_bios_table_test.cpp
+++ b/test/libpldm_bios_table_test.cpp
@@ -916,6 +916,13 @@
     destTable.resize(destLength);
     EXPECT_THAT(destTable, ElementsAreArray(expectTable));
 
+    stringEntry3[2] = PLDM_BIOS_INTEGER; // set attribute type to integer
+    rc = pldm_bios_table_attr_value_copy_and_update(
+        srcTable.data(), srcTable.size(), destTable.data(), &destLength,
+        stringEntry3.data(), stringEntry3.size());
+    EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+    stringEntry3[2] = PLDM_BIOS_STRING; // set attribute type to string
+
     destTable.resize(expectTable.size() - 1);
     destLength = destTable.size();
     rc = pldm_bios_table_attr_value_copy_and_update(