]> Git Repo - qemu.git/commitdiff
block: avoid buffer overrun by using pstrcpy, not strncpy
authorJim Meyering <[email protected]>
Thu, 4 Oct 2012 11:09:46 +0000 (13:09 +0200)
committerAnthony Liguori <[email protected]>
Fri, 5 Oct 2012 12:58:36 +0000 (07:58 -0500)
Also, use PATH_MAX, rather than the arbitrary 1024.
Using PATH_MAX is more consistent with other filename-related
variables in this file, like backing_filename and tmp_filename.

Acked-by: Kevin Wolf <[email protected]>
Signed-off-by: Jim Meyering <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
block.c

diff --git a/block.c b/block.c
index c108a76952a2f6caf72d6c1bb6631e19cc011a62..e95f613aa4882a4feade0ccf87e9b80d7d33274d 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1506,7 +1506,7 @@ int bdrv_commit(BlockDriverState *bs)
     int n, ro, open_flags;
     int ret = 0;
     uint8_t *buf;
-    char filename[1024];
+    char filename[PATH_MAX];
 
     if (!drv)
         return -ENOMEDIUM;
@@ -1520,7 +1520,8 @@ int bdrv_commit(BlockDriverState *bs)
     }
 
     ro = bs->backing_hd->read_only;
-    strncpy(filename, bs->backing_hd->filename, sizeof(filename));
+    /* Use pstrcpy (not strncpy): filename must be NUL-terminated. */
+    pstrcpy(filename, sizeof(filename), bs->backing_hd->filename);
     open_flags =  bs->backing_hd->open_flags;
 
     if (ro) {
This page took 0.029242 seconds and 4 git commands to generate.