[sheepdog-users] [PATCH stable-0.7] dog: let "dog vdi cache" subcommands parse arguments in a correct manner
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Fri Dec 20 05:38:28 CET 2013
Current subcommands of "dog vdi cache" can cause segmentation faults
because they don't check an index of argv.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
Conflicts:
dog/vdi.c
Conflicts were resolved by Hitoshi Mitake.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
dog/vdi.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/dog/vdi.c b/dog/vdi.c
index f13a31f..f4fbc67 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1991,11 +1991,19 @@ out:
static int vdi_cache_flush(int argc, char **argv)
{
- const char *vdiname = argv[optind++];
+ const char *vdiname;
struct sd_req hdr;
uint32_t vid;
int ret = EXIT_SUCCESS;
+ if (optind < argc)
+ vdiname = argv[optind++];
+ else {
+ sd_err("please specify VDI name");
+ ret = EXIT_FAILURE;
+ goto out;
+ }
+
ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag, &vid, 0);
if (ret < 0) {
@@ -2018,11 +2026,19 @@ out:
static int vdi_cache_delete(int argc, char **argv)
{
- const char *vdiname = argv[optind++];
+ const char *vdiname;
struct sd_req hdr;
uint32_t vid;
int ret = EXIT_SUCCESS;
+ if (optind < argc)
+ vdiname = argv[optind++];
+ else {
+ sd_err("please specify VDI name");
+ ret = EXIT_FAILURE;
+ goto out;
+ }
+
ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag, &vid, 0);
if (ret < 0) {
--
1.7.10.4
More information about the sheepdog-users
mailing list