Browse Source

Update for harden finds.

Brian Aker 12 years ago
parent
commit
e5ac0a7e78

+ 3 - 0
configure.ac

@@ -40,6 +40,9 @@ LT_PREREQ([2.2])
 LT_INIT([disable-static])
 LT_LANG([C++])
 
+AC_PROG_CC_C99
+AS_IF([test "x${ac_cv_prog_cc_c99}" == "xno"],[AC_MSG_ERROR([No c99 compatible compiler found])])
+
 AX_PLATFORM
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 AX_ASSERT

+ 49 - 4
libgearman/connection.cc

@@ -161,6 +161,52 @@ gearman_connection_st::gearman_connection_st(gearman_universal_st &universal_arg
   host[0]= 0;
 }
 
+gearman_connection_st::gearman_connection_st(const gearman_connection_st& copy):
+  state(GEARMAN_CON_UNIVERSAL_ADDRINFO),
+  send_state(GEARMAN_CON_SEND_STATE_NONE),
+  recv_state(GEARMAN_CON_RECV_UNIVERSAL_NONE),
+  port(copy.port),
+  events(0),
+  revents(0),
+  fd(-1),
+  cached_errno(0),
+  created_id(0),
+  created_id_next(0),
+  send_buffer_size(0),
+  send_data_size(0),
+  send_data_offset(0),
+  recv_buffer_size(0),
+  recv_data_size(0),
+  recv_data_offset(0),
+  universal(copy.universal),
+  next(NULL),
+  prev(NULL),
+  context(NULL),
+  _addrinfo(NULL),
+  addrinfo_next(NULL),
+  send_buffer_ptr(NULL),
+  _recv_packet(NULL)
+{
+  if (universal.con_list)
+  {
+    universal.con_list->prev= this;
+  }
+  next= universal.con_list;
+  universal.con_list= this;
+  universal.con_count++;
+
+  send_buffer_ptr= send_buffer;
+  recv_buffer_ptr= recv_buffer;
+  if (host[0])
+  {
+    strcpy(host, copy.host);
+  }
+  else
+  {
+    host[0]= 0;
+  }
+}
+
 gearman_connection_st *gearman_connection_create(gearman_universal_st &universal,
                                                  gearman_connection_options_t *options)
 {
@@ -373,16 +419,15 @@ gearman_return_t gearman_connection_st::send_packet(const gearman_packet_st& pac
          head= head->next)
     {
       gearman_packet_st message;
-      const void *args[]= { head->_option };
-      size_t args_size[]= { head->_option_length };
+      const void *args[]= { (void*)(head->value()) };
+      size_t args_size[]= { head->size() };
       gearman_return_t ret= gearman_packet_create_args(universal, message, GEARMAN_MAGIC_REQUEST,
                                                        GEARMAN_COMMAND_OPTION_REQ, args, args_size, 1);
 
       if (gearman_failed(ret))
       {
         gearman_packet_free(&message);
-        gearman_error(universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "gearman_packet_create_args()");
-        return GEARMAN_MEMORY_ALLOCATION_FAILURE;
+        return gearman_error(universal, GEARMAN_MEMORY_ALLOCATION_FAILURE, "gearman_packet_create_args()");
       }
 
       PUSH_BLOCKING(universal);

+ 2 - 0
libgearman/connection.hpp

@@ -128,6 +128,8 @@ public:
     _recv_packet= NULL;
   }
 
+  gearman_connection_st(const gearman_connection_st&);
+
 private:
   gearman_return_t _send_packet(const gearman_packet_st&, const bool flush_buffer);
   gearman_return_t set_socket_options();

+ 2 - 1
libgearman/result.hpp

@@ -64,7 +64,8 @@ struct gearman_result_st
 
     Value() :
       _boolean(false),
-      _integer(0)
+      _integer(0),
+      string()
     { }
 
     Value(size_t initial_size) :

+ 13 - 4
libgearman/server_options.cc

@@ -73,10 +73,11 @@ bool gearman_request_option(gearman_universal_st &universal,
 
 gearman_server_options_st::gearman_server_options_st(gearman_universal_st &universal_arg,
                                                      const char* option_arg, const size_t option_arg_size) : 
-  _option(option_arg), _option_length(option_arg_size),
+  _option(option_arg_size),
   next(NULL), prev(NULL),
   universal(universal_arg)
 {
+  _option.append(option_arg, option_arg_size);
   if (universal.server_options_list)
   {
     universal.server_options_list->prev= this;
@@ -85,13 +86,21 @@ gearman_server_options_st::gearman_server_options_st(gearman_universal_st &unive
   universal.server_options_list= this;
 }
 
-gearman_server_options_st::~gearman_server_options_st()
+gearman_server_options_st::gearman_server_options_st(const gearman_server_options_st& copy) :
+  _option(copy.option()),
+  next(NULL), prev(NULL),
+  universal(copy.universal)
 {
-  if (_option)
+  if (universal.server_options_list)
   {
-    free((void*)_option);
+    universal.server_options_list->prev= this;
   }
+  next= universal.server_options_list;
+  universal.server_options_list= this;
+}
 
+gearman_server_options_st::~gearman_server_options_st()
+{
   { // Remove from universal list
     if (universal.server_options_list == this)
     {

+ 18 - 2
libgearman/server_options.hpp

@@ -44,8 +44,7 @@ bool gearman_request_option(gearman_universal_st &universal, gearman_string_t &o
 
 struct gearman_server_options_st
 {
-  const char* _option;
-  const size_t _option_length;
+  gearman_vector_st _option;
 
   gearman_server_options_st *next;
   gearman_server_options_st *prev;
@@ -55,4 +54,21 @@ public:
   gearman_server_options_st(gearman_universal_st &universal_arg,
                             const char* option_arg, const size_t option_arg_size);
   ~gearman_server_options_st();
+
+  gearman_server_options_st(const gearman_server_options_st&);
+
+  const gearman_vector_st& option() const
+  {
+    return _option;
+  }
+
+  const char* value() const
+  {
+    return _option.value();
+  }
+
+  size_t size() const
+  {
+    return _option.size();
+  }
 };

+ 2 - 2
libgearman/vector.cc

@@ -181,7 +181,7 @@ gearman_vector_st *gearman_string_clone(const gearman_vector_st *self)
     {
       if (self->size())
       {
-        if (clone->store(gearman_string_value(self), gearman_string_length(self)) == false)
+        if (clone->store(*self) == false)
         {
           gearman_string_free(clone);
           return NULL;
@@ -259,7 +259,7 @@ bool gearman_vector_st::store(const char* arg_, const size_t arg_length_)
   return append(arg_, arg_length_);
 }
 
-bool gearman_vector_st::store(gearman_vector_st& vec)
+bool gearman_vector_st::store(const gearman_vector_st& vec)
 {
   clear();
   return append(vec.value(), vec.size());

+ 9 - 1
libgearman/vector.hpp

@@ -72,6 +72,14 @@ struct gearman_vector_st {
   {
   }
 
+  gearman_vector_st(const gearman_vector_st& copy) :
+    end(NULL),
+    string(NULL),
+    current_size(0)
+  {
+    store(copy);
+  }
+
   gearman_vector_st(const size_t reserve);
 
   ~gearman_vector_st();
@@ -108,7 +116,7 @@ struct gearman_vector_st {
     return current_size;
   }
 
-  bool store(gearman_vector_st&);
+  bool store(const gearman_vector_st&);
   bool store(const char*, const size_t);
   bool append(const char* arg_, const size_t arg_length_);
   bool append_character(const char character);

+ 4 - 4
m4/ax_harden_compiler_flags.m4

@@ -196,7 +196,7 @@ AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS],
           _APPEND_COMPILE_FLAGS_ERROR([-fPIE -pie])
           _APPEND_COMPILE_FLAGS_ERROR([-Wsizeof-pointer-memaccess])
           _APPEND_COMPILE_FLAGS_ERROR([-Wpacked])
-          _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long])
+#         _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long])
           _APPEND_COMPILE_FLAGS_ERROR([-Wunreachable-code])
 
           AS_IF([test "x$ax_enable_debug" = xno],
@@ -281,7 +281,7 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS],
           _APPEND_COMPILE_FLAGS_ERROR([-Wunsafe-loop-optimizations])
           _APPEND_COMPILE_FLAGS_ERROR([-funsafe-loop-optimizations])
           _APPEND_COMPILE_FLAGS_ERROR([-Wc++11-compat])
-          _APPEND_COMPILE_FLAGS_ERROR([-Weffc++])
+#         _APPEND_COMPILE_FLAGS_ERROR([-Weffc++])
           AS_IF([test "x$MINGW" != xyes],[
             AS_IF([test "x$ac_cv_vcs_checkout" = xyes],[
               AS_IF([test "x$enable_shared" = "xyes"],[
@@ -309,7 +309,7 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS],
               ])
             ])
           ])
-          _APPEND_COMPILE_FLAGS_ERROR([-Wold-style-cast])
+#         _APPEND_COMPILE_FLAGS_ERROR([-Wold-style-cast])
           _APPEND_COMPILE_FLAGS_ERROR([-Wclobbered])
           _APPEND_COMPILE_FLAGS_ERROR([-Wunused])
           _APPEND_COMPILE_FLAGS_ERROR([-Wunused-result])
@@ -325,7 +325,7 @@ AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS],
           _APPEND_COMPILE_FLAGS_ERROR([-fPIE -pie])
           _APPEND_COMPILE_FLAGS_ERROR([-Wsizeof-pointer-memaccess])
           _APPEND_COMPILE_FLAGS_ERROR([-Wpacked])
-          _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long])
+#         _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long])
           _APPEND_COMPILE_FLAGS_ERROR([-Wunreachable-code])
 
           AS_IF([test "x$ax_enable_debug" = xno],