From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 1/4] block: Change bdrv_get_encrypted_filename()
Date: Wed, 24 Sep 2014 21:48:24 +0200 [thread overview]
Message-ID: <1411588107-4275-2-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1411588107-4275-1-git-send-email-mreitz@redhat.com>
Instead of returning a pointer to the filename, copy it into a buffer
specified by the caller. While adapting the callers accordingly, this
patch also fixes them apparently ignoring that this function's return
value may be NULL.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block.c | 20 ++++++++++++++------
blockdev.c | 4 +++-
include/block/block.h | 2 +-
monitor.c | 7 +++++--
qmp.c | 4 +++-
5 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/block.c b/block.c
index a2fa1e1..4cf7620 100644
--- a/block.c
+++ b/block.c
@@ -4185,14 +4185,22 @@ int bdrv_is_allocated_above(BlockDriverState *top,
return 0;
}
-const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
+char *bdrv_get_encrypted_filename(BlockDriverState *bs, char *dest, size_t sz)
{
- if (bs->backing_hd && bs->backing_hd->encrypted)
- return bs->backing_file;
- else if (bs->encrypted)
- return bs->filename;
- else
+ if (sz > INT_MAX) {
+ sz = INT_MAX;
+ }
+
+ if (bs->backing_hd && bs->backing_hd->encrypted) {
+ pstrcpy(dest, sz, bs->backing_file);
+ return dest;
+ } else if (bs->encrypted) {
+ pstrcpy(dest, sz, bs->filename);
+ return dest;
+ } else {
+ dest[0] = '\0';
return NULL;
+ }
}
void bdrv_get_backing_filename(BlockDriverState *bs,
diff --git a/blockdev.c b/blockdev.c
index 450f95c..aed0519 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1616,8 +1616,10 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
error_set(errp, QERR_INVALID_PASSWORD);
}
} else {
+ char enc_filename[PATH_MAX];
+ bdrv_get_encrypted_filename(bs, enc_filename, sizeof(enc_filename));
error_set(errp, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs),
- bdrv_get_encrypted_filename(bs));
+ enc_filename);
}
} else if (password) {
error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
diff --git a/include/block/block.h b/include/block/block.h
index 3318f0d..c6e82f3 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -429,7 +429,7 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
int64_t *cluster_sector_num,
int *cluster_nb_sectors);
-const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
+char *bdrv_get_encrypted_filename(BlockDriverState *bs, char *dest, size_t sz);
void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size);
void bdrv_get_full_backing_filename(BlockDriverState *bs,
diff --git a/monitor.c b/monitor.c
index 667efb7..217d91e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -5382,6 +5382,7 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
BlockDriverCompletionFunc *completion_cb,
void *opaque)
{
+ char enc_filename[PATH_MAX];
int err;
if (!bdrv_key_required(bs)) {
@@ -5390,14 +5391,16 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
return 0;
}
+ bdrv_get_encrypted_filename(bs, enc_filename, sizeof(enc_filename));
+
if (monitor_ctrl_mode(mon)) {
qerror_report(QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs),
- bdrv_get_encrypted_filename(bs));
+ enc_filename);
return -1;
}
monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs),
- bdrv_get_encrypted_filename(bs));
+ enc_filename);
mon->password_completion_cb = completion_cb;
mon->password_opaque = opaque;
diff --git a/qmp.c b/qmp.c
index c6767c4..f8ca3d1 100644
--- a/qmp.c
+++ b/qmp.c
@@ -164,9 +164,11 @@ void qmp_cont(Error **errp)
}
for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
if (bdrv_key_required(bs)) {
+ char enc_filename[PATH_MAX];
+ bdrv_get_encrypted_filename(bs, enc_filename, sizeof(enc_filename));
error_set(errp, QERR_DEVICE_ENCRYPTED,
bdrv_get_device_name(bs),
- bdrv_get_encrypted_filename(bs));
+ enc_filename);
return;
}
}
--
2.1.0
next prev parent reply other threads:[~2014-09-24 19:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-24 19:48 [Qemu-devel] [PATCH 0/4] block: Drop BDS.filename Max Reitz
2014-09-24 19:48 ` Max Reitz [this message]
2014-09-24 19:48 ` [Qemu-devel] [PATCH 2/4] block: Avoid BlockDriverState.filename Max Reitz
2014-09-24 19:48 ` [Qemu-devel] [PATCH 3/4] block: Add bdrv_filename() Max Reitz
2014-09-24 19:48 ` [Qemu-devel] [PATCH 4/4] block: Drop BlockDriverState.filename Max Reitz
2015-02-03 9:32 ` [Qemu-devel] [PATCH 0/4] block: Drop BDS.filename Kevin Wolf
2015-02-03 13:48 ` Max Reitz
2015-02-03 14:40 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411588107-4275-2-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).