[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 2/2] NUL-terminate buffer before printing (found by Coverity).



From: "Richard W.M. Jones" <rjones redhat com>

---
 helper/ext2cpio.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/helper/ext2cpio.c b/helper/ext2cpio.c
index 82cc3b4..9e434c3 100644
--- a/helper/ext2cpio.c
+++ b/helper/ext2cpio.c
@@ -98,8 +98,12 @@ parse_next_entry (void)
     error (EXIT_FAILURE, errno, "read failure reading cpio file");
   curr += sizeof header - 4;
 
-  if (verbose >= 2)
-    fprintf (stderr, "cpio header %s\n", header);
+  if (verbose >= 2) {
+    char header2[sizeof header + 1];
+    memcpy (header2, header, sizeof header);
+    header2[sizeof header] = '\0';
+    fprintf (stderr, "cpio header %s\n", header2);
+  }
 
   if (memcmp (header, "070707", 6) == 0)
     error (EXIT_FAILURE, 0, "incorrect cpio method: use -H newc option");
-- 
1.7.9.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]