]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: use a vector for options passed to civetweb 14750/head
authorAbhishek Lekshmanan <abhishek@suse.com>
Tue, 25 Apr 2017 12:46:09 +0000 (14:46 +0200)
committerAbhishek Lekshmanan <abhishek@suse.com>
Wed, 26 Apr 2017 15:05:40 +0000 (17:05 +0200)
Since the array we used needs additional check to ensure that the size
is correct, and causes undefined behaviour in a few platforms, using a
vector and passing the c array back to mg_start so that we don't go past
the end of array.

Fixes: http://tracker.ceph.com/issues/19749
Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
Signed-off-by: Jesse Williamson <jwilliamson@suse.de>
src/rgw/rgw_civetweb_frontend.cc

index c564d0e492038448bd86947b8346755d1352e87b..a18a6c5da41346d771771f5f4de82c042749d196 100644 (file)
@@ -66,32 +66,30 @@ int RGWCivetWebFrontend::run()
 
   /* Prepare options for CivetWeb. */
   const std::set<boost::string_ref> rgw_opts = { "port", "prefix" };
-  const size_t CW_NUM_OPTS = 2 * (conf_map.size() - rgw_opts.size()) + 1;
-  const char *options[CW_NUM_OPTS];
-  size_t i = 0;
+
+  std::vector<const char*> options;
 
   for (const auto& pair : conf_map) {
     if (! rgw_opts.count(pair.first)) {
       /* CivetWeb doesn't understand configurables of the glue layer between
        * it and RadosGW. We need to strip them out. Otherwise CivetWeb would
        * signalise an error. */
-      options[i + 0] = pair.first.c_str();
-      options[i + 1] = pair.second.c_str();
+      options.push_back(pair.first.c_str());
+      options.push_back(pair.second.c_str());
 
-      dout(20) << "civetweb config: " << options[i] << ": "
-               << (options[i + 1] ? options[i + 1] : "<null>") << dendl;
-      i += 2;
+      dout(20) << "civetweb config: " << pair.first
+               << ": " << pair.second << dendl;
     }
   }
-  options[i] = nullptr;
 
+  options.push_back(nullptr);
   /* Initialize the CivetWeb right now. */
   struct mg_callbacks cb;
   memset((void *)&cb, 0, sizeof(cb));
   cb.begin_request = civetweb_callback;
   cb.log_message = rgw_civetweb_log_callback;
   cb.log_access = rgw_civetweb_log_access_callback;
-  ctx = mg_start(&cb, this, (const char **)&options);
+  ctx = mg_start(&cb, this, options.data());
 
   return ! ctx ? -EIO : 0;
 } /* RGWCivetWebFrontend::run */