From 419e8284c8b918558b20bc1e2194ad2cbdd5d58b Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 27 Jun 2017 11:37:24 +0200 Subject: [PATCH] coverity: validate length of renaming path Make sure path fits into buffer on stack. --- lib/format_text/format-text.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 533fece26..5d731cad6 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -1043,6 +1043,11 @@ static int _vg_commit_file(struct format_instance *fid, struct volume_group *vg, if (strcmp(slash, vg->name)) { len = slash - tc->path_live; + if ((len + strlen(vg->name)) > (sizeof(new_name) - 1)) { + log_error("Renaming path %s is too long for VG %s.", + tc->path_live, vg->name); + return 0; + } strncpy(new_name, tc->path_live, len); strcpy(new_name + len, vg->name); log_debug_metadata("Renaming %s to %s", tc->path_live, new_name);