[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.9 03/10] rbd: Don't limit length of parameter v
From: |
Jeff Cody |
Subject: |
[Qemu-devel] [PULL for-2.9 03/10] rbd: Don't limit length of parameter values |
Date: |
Tue, 28 Mar 2017 10:05:48 -0400 |
From: Markus Armbruster <address@hidden>
We laboriously enforce that parameter values are between one and some
arbitrary limit in length. Only RBD_MAX_IMAGE_NAME_SIZE comes from
librbd.h, and I'm not sure it applies. Where the other limits come
from is unclear.
Drop the length checking. The limits librbd actually imposes must be
checked by librbd anyway.
There's one minor complication: BDRVRBDState member name is a
fixed-size array. Depends on the length limit. Make it a pointer to
a dynamically allocated string.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Message-id: address@hidden
Signed-off-by: Jeff Cody <address@hidden>
---
block/rbd.c | 91 ++++++++++---------------------------------------------------
1 file changed, 14 insertions(+), 77 deletions(-)
diff --git a/block/rbd.c b/block/rbd.c
index 5ba2a87..0fea348 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -56,11 +56,6 @@
#define OBJ_MAX_SIZE (1UL << OBJ_DEFAULT_OBJ_ORDER)
-#define RBD_MAX_CONF_NAME_SIZE 128
-#define RBD_MAX_CONF_VAL_SIZE 512
-#define RBD_MAX_CONF_SIZE 1024
-#define RBD_MAX_POOL_NAME_SIZE 128
-#define RBD_MAX_SNAP_NAME_SIZE 128
#define RBD_MAX_SNAPS 100
/* The LIBRBD_SUPPORTS_IOVEC is defined in librbd.h */
@@ -99,16 +94,12 @@ typedef struct BDRVRBDState {
rados_t cluster;
rados_ioctx_t io_ctx;
rbd_image_t image;
- char name[RBD_MAX_IMAGE_NAME_SIZE];
+ char *name;
char *snap;
} BDRVRBDState;
-static char *qemu_rbd_next_tok(int max_len,
- char *src, char delim,
- const char *name,
- char **p, Error **errp)
+static char *qemu_rbd_next_tok(char *src, char delim, char **p)
{
- int l;
char *end;
*p = NULL;
@@ -127,15 +118,6 @@ static char *qemu_rbd_next_tok(int max_len,
*end = '\0';
}
}
- l = strlen(src);
- if (l >= max_len) {
- error_setg(errp, "%s too long", name);
- return NULL;
- } else if (l == 0) {
- error_setg(errp, "%s too short", name);
- return NULL;
- }
-
return src;
}
@@ -159,7 +141,6 @@ static void qemu_rbd_parse_filename(const char *filename,
QDict *options,
char *p, *buf, *keypairs;
char *found_str;
size_t max_keypair_size;
- Error *local_err = NULL;
if (!strstart(filename, "rbd:", &start)) {
error_setg(errp, "File name must start with 'rbd:'");
@@ -171,11 +152,7 @@ static void qemu_rbd_parse_filename(const char *filename,
QDict *options,
keypairs = g_malloc0(max_keypair_size);
p = buf;
- found_str = qemu_rbd_next_tok(RBD_MAX_POOL_NAME_SIZE, p,
- '/', "pool name", &p, &local_err);
- if (local_err) {
- goto done;
- }
+ found_str = qemu_rbd_next_tok(p, '/', &p);
if (!p) {
error_setg(errp, "Pool name is required");
goto done;
@@ -184,27 +161,15 @@ static void qemu_rbd_parse_filename(const char *filename,
QDict *options,
qdict_put(options, "pool", qstring_from_str(found_str));
if (strchr(p, '@')) {
- found_str = qemu_rbd_next_tok(RBD_MAX_IMAGE_NAME_SIZE, p,
- '@', "object name", &p, &local_err);
- if (local_err) {
- goto done;
- }
+ found_str = qemu_rbd_next_tok(p, '@', &p);
qemu_rbd_unescape(found_str);
qdict_put(options, "image", qstring_from_str(found_str));
- found_str = qemu_rbd_next_tok(RBD_MAX_SNAP_NAME_SIZE, p,
- ':', "snap name", &p, &local_err);
- if (local_err) {
- goto done;
- }
+ found_str = qemu_rbd_next_tok(p, ':', &p);
qemu_rbd_unescape(found_str);
qdict_put(options, "snapshot", qstring_from_str(found_str));
} else {
- found_str = qemu_rbd_next_tok(RBD_MAX_IMAGE_NAME_SIZE, p,
- ':', "object name", &p, &local_err);
- if (local_err) {
- goto done;
- }
+ found_str = qemu_rbd_next_tok(p, ':', &p);
qemu_rbd_unescape(found_str);
qdict_put(options, "image", qstring_from_str(found_str));
}
@@ -212,11 +177,7 @@ static void qemu_rbd_parse_filename(const char *filename,
QDict *options,
goto done;
}
- found_str = qemu_rbd_next_tok(RBD_MAX_CONF_NAME_SIZE, p,
- '\0', "configuration", &p, &local_err);
- if (local_err) {
- goto done;
- }
+ found_str = qemu_rbd_next_tok(p, '\0', &p);
p = found_str;
@@ -224,12 +185,7 @@ static void qemu_rbd_parse_filename(const char *filename,
QDict *options,
* 'id' and 'conf' a bit special. Key/value pairs may be in any order. */
while (p) {
char *name, *value;
- name = qemu_rbd_next_tok(RBD_MAX_CONF_NAME_SIZE, p,
- '=', "conf option name", &p, &local_err);
- if (local_err) {
- break;
- }
-
+ name = qemu_rbd_next_tok(p, '=', &p);
if (!p) {
error_setg(errp, "conf option %s has no value", name);
break;
@@ -237,11 +193,7 @@ static void qemu_rbd_parse_filename(const char *filename,
QDict *options,
qemu_rbd_unescape(name);
- value = qemu_rbd_next_tok(RBD_MAX_CONF_VAL_SIZE, p,
- ':', "conf option value", &p, &local_err);
- if (local_err) {
- break;
- }
+ value = qemu_rbd_next_tok(p, ':', &p);
qemu_rbd_unescape(value);
if (!strcmp(name, "conf")) {
@@ -274,9 +226,6 @@ static void qemu_rbd_parse_filename(const char *filename,
QDict *options,
done:
- if (local_err) {
- error_propagate(errp, local_err);
- }
g_free(buf);
g_free(keypairs);
return;
@@ -308,30 +257,20 @@ static int qemu_rbd_set_keypairs(rados_t cluster, const
char *keypairs,
char *p, *buf;
char *name;
char *value;
- Error *local_err = NULL;
int ret = 0;
buf = g_strdup(keypairs);
p = buf;
while (p) {
- name = qemu_rbd_next_tok(RBD_MAX_CONF_NAME_SIZE, p,
- '=', "conf option name", &p, &local_err);
- if (local_err) {
- break;
- }
-
+ name = qemu_rbd_next_tok(p, '=', &p);
if (!p) {
error_setg(errp, "conf option %s has no value", name);
ret = -EINVAL;
break;
}
- value = qemu_rbd_next_tok(RBD_MAX_CONF_VAL_SIZE, p,
- ':', "conf option value", &p, &local_err);
- if (local_err) {
- break;
- }
+ value = qemu_rbd_next_tok(p, ':', &p);
ret = rados_conf_set(cluster, name, value);
if (ret < 0) {
@@ -341,10 +280,6 @@ static int qemu_rbd_set_keypairs(rados_t cluster, const
char *keypairs,
}
}
- if (local_err) {
- error_propagate(errp, local_err);
- ret = -EINVAL;
- }
g_free(buf);
return ret;
}
@@ -724,7 +659,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict
*options, int flags,
}
s->snap = g_strdup(snap);
- pstrcpy(s->name, RBD_MAX_IMAGE_NAME_SIZE, name);
+ s->name = g_strdup(name);
/* try default location when conf=NULL, but ignore failure */
r = rados_conf_read_file(s->cluster, conf);
@@ -798,6 +733,7 @@ failed_open:
failed_shutdown:
rados_shutdown(s->cluster);
g_free(s->snap);
+ g_free(s->name);
failed_opts:
qemu_opts_del(opts);
g_free(mon_host);
@@ -812,6 +748,7 @@ static void qemu_rbd_close(BlockDriverState *bs)
rbd_close(s->image);
rados_ioctx_destroy(s->io_ctx);
g_free(s->snap);
+ g_free(s->name);
rados_shutdown(s->cluster);
}
--
2.9.3
- [Qemu-devel] [PULL for-2.9 00/10] Block patches for -rc2, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 01/10] rbd: Reject -blockdev server.*.{numeric, to, ipv4, ipv6}, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 04/10] rbd: Clean up after the previous commit, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 03/10] rbd: Don't limit length of parameter values,
Jeff Cody <=
- [Qemu-devel] [PULL for-2.9 02/10] rbd: Fix to cleanly reject -drive without pool or image, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 07/10] rbd: Clean up qemu_rbd_create()'s detour through QemuOpts, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 05/10] rbd: Don't accept -drive driver=rbd, keyvalue-pairs=..., Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 06/10] rbd: Clean up runtime_opts, fix -drive to reject filename, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 08/10] rbd: Revert -blockdev and -drive parameter auth-supported, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 09/10] rbd: Revert -blockdev parameter password-secret, Jeff Cody, 2017/03/28
- [Qemu-devel] [PULL for-2.9 10/10] rbd: Fix bugs around -drive parameter "server", Jeff Cody, 2017/03/28
- Re: [Qemu-devel] [PULL for-2.9 00/10] Block patches for -rc2, Peter Maydell, 2017/03/28