]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/internal.cc: check earlier for null pointer
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Wed, 4 Jun 2014 21:22:18 +0000 (23:22 +0200)
committerJosh Durgin <josh.durgin@inktank.com>
Sat, 9 Aug 2014 23:34:11 +0000 (16:34 -0700)
Fix potential null ponter deref, move check for 'order != NULL'
to the beginning of the function to prevent a) deref in ldout() call
and b) to leave function as early as possible if check fails.

[src/librbd/internal.cc:843] -> [src/librbd/internal.cc:865]: (warning)
 Possible null pointer dereference: order - otherwise it is redundant
 to check it against null.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
(cherry picked from commit 3ee3e66a9520a5fcafa7d8c632586642f7bdbd29)

src/librbd/internal.cc

index e56ef0897f48c3ddf5e7766f01f95a7592a3a588..36cddf80616d8d5ad4761607bf78f71f46d50202 100644 (file)
@@ -832,6 +832,9 @@ reprotect_and_return_err:
             bool old_format, uint64_t features, int *order,
             uint64_t stripe_unit, uint64_t stripe_count)
   {
+    if (!order)
+      return -EINVAL;
+
     CephContext *cct = (CephContext *)io_ctx.cct();
     ldout(cct, 20) << "create " << &io_ctx << " name = " << imgname
                   << " size = " << size << " old_format = " << old_format
@@ -857,9 +860,6 @@ reprotect_and_return_err:
       return -EEXIST;
     }
 
-    if (!order)
-      return -EINVAL;
-
     if (!*order)
       *order = cct->_conf->rbd_default_order;
     if (!*order)