7 Star 0 Fork 26

src-openEuler/parted

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0006-scsi_get_product_info-fix-memleak-and-avoid-to-use-N.patch 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
Li Jinlin 提交于 2022-03-29 11:17 +08:00 . fix memory leak in libparted
From 1fdae37b82d0cf16df80f648b5489f7ffd15eae1 Mon Sep 17 00:00:00 2001
From: Li Jinlin <lijinlin3@huawei.com>
Date: Tue, 29 Mar 2022 11:02:38 +0800
Subject: [PATCH 3/6] scsi_get_product_info: fix memleak and avoid to use NULL
pointer
Need to ensure that *vendor and *product are not NULL in scsi_query_product_info()
before return 1, otherwise a null pointer may be used.
Regardless of whether scsi_query_product_info() returns success or failed,
vendor and product should be released, otherwise there will be a memory leak
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Li Jinlin <lijinlin3@huawei.com>
---
libparted/arch/linux.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 94ea176..23ec55a 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -1130,7 +1130,9 @@ scsi_query_product_info (PedDevice* dev, char **vendor, char **product)
buf[16] = '\0';
*product = strip_name (buf);
- return 1;
+ if (*vendor && *product)
+ return 1;
+ return 0;
}
/* This function provides the vendor and product name for a SCSI device.
@@ -1144,7 +1146,6 @@ scsi_get_product_info (PedDevice* dev, char **vendor, char **product)
*product = read_device_sysfs_file (dev, "model");
if (*vendor && *product)
return 1;
-
return scsi_query_product_info (dev, vendor, product);
}
@@ -1188,11 +1189,11 @@ init_scsi (PedDevice* dev)
if (scsi_get_product_info (dev, &vendor, &product)) {
sprintf (dev->model, "%.8s %.16s", vendor, product);
- free (vendor);
- free (product);
} else {
strcpy (dev->model, "Generic SCSI");
}
+ free (vendor);
+ free (product);
if (!_device_probe_geometry (dev))
goto error_close_dev;
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/parted.git
git@gitee.com:src-openeuler/parted.git
src-openeuler
parted
parted
master

搜索帮助