dynamic-partition: liblp: Fix an abnormal completion to do strncpy 04/308404/2 accepted/tizen/unified/20240325.141306 accepted/tizen/unified/x/20240327.045004
authorJaehoon Chung <jh80.chung@samsung.com>
Mon, 25 Mar 2024 02:12:31 +0000 (11:12 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 25 Mar 2024 06:19:25 +0000 (15:19 +0900)
Fix an abnormal completion to do strncpy.
Use deviceinfo.partition_name.size instead of sizeof(out.partiton_name).

Change-Id: I8b3605f609a731f5529b1e6b1b8702fb549e08d5
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
src/dynamic-partitions/liblp/builder.cpp

index 6743910588af1798db20b5f50dab226850d6ef59..1d864410079da73272d87e8b4cb02c23f8048247 100644 (file)
@@ -325,11 +325,11 @@ bool MetadataBuilder::Init(const std::vector<BlockDeviceInfo>& block_devices,
         out.alignment = device_info.alignment;
         out.alignment_offset = device_info.alignment_offset;
         out.size = device_info.size;
-        if (device_info.partition_name.size() > sizeof(out.partition_name)) {
+        if (device_info.partition_name.size() >= sizeof(out.partition_name)) {
             LERROR << "Partition name " << device_info.partition_name << " exceeds maximum length.";
             return false;
         }
-        strncpy(out.partition_name, device_info.partition_name.c_str(), sizeof(out.partition_name));
+        strncpy(out.partition_name, device_info.partition_name.c_str(), device_info.partition_name.size());
 
         // In the case of the super partition, this field will be adjusted
         // later. For all partitions, the first 512 bytes are considered