[sheepdog] [PATCH] dog: let "dog vdi cache" subcommands parse arguments in a correct manner
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Fri Dec 20 02:56:34 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>
---
dog/vdi.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/dog/vdi.c b/dog/vdi.c
index c716589..b6c955c 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -2252,11 +2252,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) {
@@ -2279,11 +2287,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) {
@@ -2370,7 +2386,7 @@ static int vdi_cache_purge(int argc, char **argv)
sd_init_req(&hdr, SD_OP_CACHE_PURGE);
- if (argc == 5) {
+ if (optind < argc) {
vdiname = argv[optind++];
ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag, &vid, 0);
--
1.7.10.4
More information about the sheepdog
mailing list