summaryrefslogtreecommitdiffstats
path: root/mapfile.c
diff options
context:
space:
mode:
authorAnna Sztukowska <anna.sztukowska@intel.com>2024-07-03 14:11:58 +0200
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-07-10 16:14:12 +0200
commit48c365376ce7763fd9a9e7735b1e9ec5d0ff1631 (patch)
tree0b625d6ec60ebc5899f7a0f12060d382f2fde959 /mapfile.c
parentmdadm/clustermd_tests: adjust test cases to support md module changes (diff)
downloadmdadm-48c365376ce7763fd9a9e7735b1e9ec5d0ff1631.tar.xz
mdadm-48c365376ce7763fd9a9e7735b1e9ec5d0ff1631.zip
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>
Diffstat (limited to 'mapfile.c')
-rw-r--r--mapfile.c6
1 files 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;