From: Josh Durgin Date: Mon, 24 Sep 2012 21:49:27 +0000 (-0700) Subject: rbd: make sure we have a device before trying to unmap X-Git-Tag: v0.53~41^2~33 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=68b1fd66e9a71dfec60612c571ad4674d0e3542c;p=ceph.git rbd: make sure we have a device before trying to unmap CID 717444: Explicit null dereferenced (FORWARD_NULL) At (48): Passing null pointer "devpath" to function "do_kernel_rm(char const *)", which dereferences it. Signed-off-by: Josh Durgin --- diff --git a/src/rbd.cc b/src/rbd.cc index 478b15e46a956..5d1615581837a 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -1375,6 +1375,12 @@ int main(int argc, const char **argv) return EXIT_FAILURE; } + if (opt_cmd == OPT_UNMAP && !devpath) { + cerr << "error: device path was not specified" << std::endl; + usage(); + return EXIT_FAILURE; + } + // do this unconditionally so we can parse pool/image@snapshot into // the relevant parts set_pool_image_name(poolname, imgname, (char **)&poolname, diff --git a/src/test/cli/rbd/bad-map.t b/src/test/cli/rbd/bad-map.t new file mode 100644 index 0000000000000..590441eea22a5 --- /dev/null +++ b/src/test/cli/rbd/bad-map.t @@ -0,0 +1,120 @@ + $ rbd map + error: image name was not specified + usage: rbd [-n ] [OPTIONS] ... + where 'pool' is a rados pool name (default is 'rbd') and 'cmd' is one of: + (ls | list) [pool-name] list rbd images + info show information about image size, + striping, etc. + create [--order ] --size create an empty image + clone [--order ] + clone a snapshot into a COW + child image + children display children of snapshot + flatten fill clone with parent data + (make it independent) + resize --size resize (expand or contract) image + rm delete an image + export export image to file + import import image from file + (dest defaults) + as the filename part of file) + (cp | copy) copy src image to dest + (mv | rename) rename src image to dest + snap ls dump list of image snapshots + snap create create a snapshot + snap rollback rollback image to snapshot + snap rm deletes a snapshot + snap purge deletes all snapshots + snap protect prevent a snapshot from being deleted + snap unprotect allow a snapshot to be deleted + watch watch events on image + map map image to a block device + using the kernel + unmap unmap a rbd device that was + mapped by the kernel + showmapped show the rbd images mapped + by the kernel + lock list show locks held on an image + lock add [--shared ] take a lock called id on an image + lock remove release a lock on an image + + , are [pool/]name[@snap], or you may specify + individual pieces of names with -p/--pool, --image, and/or --snap. + + Other input options: + -p, --pool source pool name + --image image name + --dest destination [pool and] image name + --snap snapshot name + --dest-pool destination pool name + --path path name for import/export + --size size of image for create and resize + --order the object size in bits; object size will be + (1 << order) bytes. Default is 22 (4 MB). + --format format to use when creating an image + format 1 is the original format (default) + format 2 supports cloning + --id rados user (without 'client.' prefix) to authenticate as + --keyfile file containing secret key for use with cephx + --shared take a shared (rather than exclusive) lock + [1] + $ rbd unmap + error: device path was not specified + usage: rbd [-n ] [OPTIONS] ... + where 'pool' is a rados pool name (default is 'rbd') and 'cmd' is one of: + (ls | list) [pool-name] list rbd images + info show information about image size, + striping, etc. + create [--order ] --size create an empty image + clone [--order ] + clone a snapshot into a COW + child image + children display children of snapshot + flatten fill clone with parent data + (make it independent) + resize --size resize (expand or contract) image + rm delete an image + export export image to file + import import image from file + (dest defaults) + as the filename part of file) + (cp | copy) copy src image to dest + (mv | rename) rename src image to dest + snap ls dump list of image snapshots + snap create create a snapshot + snap rollback rollback image to snapshot + snap rm deletes a snapshot + snap purge deletes all snapshots + snap protect prevent a snapshot from being deleted + snap unprotect allow a snapshot to be deleted + watch watch events on image + map map image to a block device + using the kernel + unmap unmap a rbd device that was + mapped by the kernel + showmapped show the rbd images mapped + by the kernel + lock list show locks held on an image + lock add [--shared ] take a lock called id on an image + lock remove release a lock on an image + + , are [pool/]name[@snap], or you may specify + individual pieces of names with -p/--pool, --image, and/or --snap. + + Other input options: + -p, --pool source pool name + --image image name + --dest destination [pool and] image name + --snap snapshot name + --dest-pool destination pool name + --path path name for import/export + --size size of image for create and resize + --order the object size in bits; object size will be + (1 << order) bytes. Default is 22 (4 MB). + --format format to use when creating an image + format 1 is the original format (default) + format 2 supports cloning + --id rados user (without 'client.' prefix) to authenticate as + --keyfile file containing secret key for use with cephx + --shared take a shared (rather than exclusive) lock + [1]