Skip to contentSkip to conversation

master - coverity: validate length of renaming path

PATCH Zdenek Kabelac 1 participant 1 message Jun 27, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=419e8284c8b918558b20bc1e2194ad2cbdd5d58b
Commit:        419e8284c8b918558b20bc1e2194ad2cbdd5d58b
Parent:        8e790702f12ddcb730f8dc43d3fdccf08e62aa45
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Tue Jun 27 11:37:24 2017 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Tue Jun 27 12:15:42 2017 +0200

coverity: validate length of renaming path

Make sure path fits into buffer on stack.

---
 lib/format_text/format-text.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
lib/format_text/format-text.c +5 -0
index 533fece..5d731ca 100644
@@ -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);