Skip to content

Commit 05cc758

Browse files
committed
blkverify: Catch bs->exact_filename overflow
The bs->exact_filename field may not be sufficient to store the full blkverify node filename. In this case, we should not generate a filename at all instead of an unusable one. Cc: [email protected] Reported-by: Qu Wenruo <[email protected]> Signed-off-by: Max Reitz <[email protected]> Message-id: [email protected] Reviewed-by: Alberto Garcia <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Max Reitz <[email protected]>
1 parent de81d72 commit 05cc758

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

block/blkverify.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,14 @@ static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options)
301301
if (bs->file->bs->exact_filename[0]
302302
&& s->test_file->bs->exact_filename[0])
303303
{
304-
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
305-
"blkverify:%s:%s",
306-
bs->file->bs->exact_filename,
307-
s->test_file->bs->exact_filename);
304+
int ret = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
305+
"blkverify:%s:%s",
306+
bs->file->bs->exact_filename,
307+
s->test_file->bs->exact_filename);
308+
if (ret >= sizeof(bs->exact_filename)) {
309+
/* An overflow makes the filename unusable, so do not report any */
310+
bs->exact_filename[0] = 0;
311+
}
308312
}
309313
}
310314

0 commit comments

Comments
 (0)