加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0023-mapfile.c-Fix-STRING_OVERFLOW-issue.patch 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
wguanghao 提交于 2024-08-26 15:49 . backport bugfix patches from community
From 48c365376ce7763fd9a9e7735b1e9ec5d0ff1631 Mon Sep 17 00:00:00 2001
From: Anna Sztukowska <anna.sztukowska@intel.com>
Date: Wed, 3 Jul 2024 14:11:58 +0200
Subject: [PATCH] mapfile.c: Fix STRING_OVERFLOW issue
Fix STRING_OVERFLOW issue found by SAST analysis in map_add() and
map_update() in mapfile.c.
Signed-off-by: Anna Sztukowska <anna.sztukowska@intel.com>
---
mapfile.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mapfile.c b/mapfile.c
index f1f3ee2c..ea9837ac 100644
--- a/mapfile.c
+++ b/mapfile.c
@@ -165,8 +165,8 @@ void map_add(struct map_ent **melp,
{
struct map_ent *me = xmalloc(sizeof(*me));
- strcpy(me->devnm, devnm);
- strcpy(me->metadata, metadata);
+ snprintf(me->devnm, sizeof(me->devnm), "%s", devnm);
+ snprintf(me->metadata, sizeof(me->metadata), "%s", metadata);
memcpy(me->uuid, uuid, 16);
me->path = path ? xstrdup(path) : NULL;
me->next = *melp;
@@ -227,7 +227,7 @@ int map_update(struct map_ent **mpp, char *devnm, char *metadata,
for (mp = map ; mp ; mp=mp->next)
if (strcmp(mp->devnm, devnm) == 0) {
- strcpy(mp->metadata, metadata);
+ snprintf(mp->metadata, sizeof(mp->metadata), "%s", metadata);
memcpy(mp->uuid, uuid, 16);
free(mp->path);
mp->path = path ? xstrdup(path) : NULL;
--
2.39.2
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化