Fix for md5
authorBrian Aker <brian@tangent.org>
Mon, 11 Mar 2013 10:20:51 +0000 (03:20 -0700)
committerBrian Aker <brian@tangent.org>
Mon, 11 Mar 2013 10:20:51 +0000 (03:20 -0700)
21 files changed:
bootstrap.sh
clients/memaslap.c
clients/memcapable.cc
clients/memerror.cc
clients/memflush.cc
clients/memping.cc
clients/memrm.cc
clients/memslap.cc
clients/memtouch.cc
clients/ms_conn.c
libmemcached/parse.cc
libmemcached/response.cc
libmemcached/stats.cc
libmemcachedprotocol/ascii_handler.c
libtest/lite.h
libtest/main.cc
libtest/memcached.hpp
libtest/unittest.cc
tests/libmemcached-1.0/all_tests.h
tests/libmemcached-1.0/mem_functions.cc
tests/libmemcached-1.0/mem_functions.h

index 42c2157b4862a164f18747190400275c4b2757ff..a368197aaa77470a5b52705e10226047faabab0a 100755 (executable)
@@ -808,7 +808,7 @@ function make_for_continuus_integration ()
 
       make_install_system
       ;;
-    *-precise-*)
+    *-ubuntu-quantal-*)
       run_configure
 
       assert_exec_file 'configure'
index 1b5c223a68c05aab1ac9991ce231b9efa4f6d14d..02907945459729a1caf05240741a95b514258731 100644 (file)
@@ -378,7 +378,13 @@ static int64_t ms_parse_size()
   char unit= optarg[strlen(optarg) - 1];
 
   optarg[strlen(optarg) - 1]= '\0';
+  errno= 0;
   ret= strtoll(optarg, (char **)NULL, 10);
+  if (errno != 0)
+  {
+    fprintf(stderr, "strtoll(optarg,..): %s\n", strerror(errno));
+    exit(1);
+  }
 
   switch (unit)
   {
@@ -434,8 +440,9 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_CONCURRENCY:       /* --concurrency or -c */
+      errno= 0;
       ms_setting.nconns= (uint32_t)strtoul(optarg, (char **) NULL, 10);
-      if (ms_setting.nconns <= 0)
+      if (ms_setting.nconns <= 0 || errno != 0)
       {
         fprintf(stderr, "Concurrency must be greater than 0.:-)\n");
         exit(1);
@@ -443,8 +450,9 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXECUTE_NUMBER:        /* --execute_number or -x */
+      errno= 0;
       ms_setting.exec_num= (int)strtol(optarg, (char **) NULL, 10);
-      if (ms_setting.exec_num <= 0)
+      if (ms_setting.exec_num <= 0 || errno != 0)
       {
         fprintf(stderr, "Execute number must be greater than 0.:-)\n");
         exit(1);
@@ -452,8 +460,9 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_THREAD_NUMBER:     /* --threads or -T */
+      errno= 0;
       ms_setting.nthreads= (uint32_t)strtoul(optarg, (char **) NULL, 10);
-      if (ms_setting.nthreads <= 0)
+      if (ms_setting.nthreads <= 0 || errno != 0)
       {
         fprintf(stderr, "Threads number must be greater than 0.:-)\n");
         exit(1);
@@ -461,8 +470,9 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_FIXED_LTH:         /* --fixed_size or -X */
+      errno= 0;
       ms_setting.fixed_value_size= (size_t)strtoull(optarg, (char **) NULL, 10);
-      if ((ms_setting.fixed_value_size <= 0)
+      if ((ms_setting.fixed_value_size <= 0 || errno != 0)
           || (ms_setting.fixed_value_size > MAX_VALUE_SIZE))
       {
         fprintf(stderr, "Value size must be between 0 and 1M.:-)\n");
@@ -482,8 +492,9 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_GETS_DIVISION:         /* --division or -d */
+      errno= 0;
       ms_setting.mult_key_num= (int)strtol(optarg, (char **) NULL, 10);
-      if (ms_setting.mult_key_num <= 0)
+      if (ms_setting.mult_key_num <= 0 || errno != 0)
       {
         fprintf(stderr, "Multi-get key number must be greater than 0.:-)\n");
         exit(1);
@@ -568,8 +579,9 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_SOCK_PER_CONN:         /* --conn_sock or -n */
+      errno= 0;
       ms_setting.sock_per_conn= (uint32_t)strtoul(optarg, (char **) NULL, 10);
-      if (ms_setting.sock_per_conn <= 0)
+      if (ms_setting.sock_per_conn <= 0 || errno != 0)
       {
         fprintf(stderr, "Number of socks of each concurrency "
                         "must be greater than 0.:-)\n");
@@ -605,8 +617,9 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_REP_WRITE_SRV:         /* --rep_write or -p */
+      errno= 0;
       ms_setting.rep_write_srv= (uint32_t)strtoul(optarg, (char **) NULL, 10);
-      if (ms_setting.rep_write_srv <= 0)
+      if (ms_setting.rep_write_srv <= 0 || errno != 0)
       {
         fprintf(stderr,
                 "Number of replication writing server must be greater "
index 0343e15d5d840663a0035727fdf68b4651345d6a..b38cf311001cbae26ebe2f12a272fe507828181f 100644 (file)
@@ -1389,11 +1389,15 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_
   verify(*key != NULL);
   char *ptr= end + 1;
 
+  errno= 0;
   unsigned long val= strtoul(ptr, &end, 10); /* flags */
+  verify(errno == 0);
   verify(ptr != end);
   verify(val == 0);
   verify(end != NULL);
+  errno= 0;
   *ndata = (ssize_t)strtoul(end, &end, 10); /* size */
+  verify(errno == 0);
   verify(ptr != end);
   verify(end != NULL);
   while (end and *end != '\n' and isspace(*end))
@@ -1424,11 +1428,16 @@ static enum test_return ascii_get_value(const char *key, const char *value)
   char *ptr= buffer + 6 + strlen(key) + 1;
   char *end;
 
+  errno= 0;
   unsigned long val= strtoul(ptr, &end, 10); /* flags */
+  verify(errno == 0);
   verify(ptr != end);
   verify(val == 0);
   verify(end != NULL);
+
+  errno= 0;
   val= strtoul(end, &end, 10); /* size */
+  verify(errno == 0);
   verify(ptr != end);
   verify(val == datasize);
   verify(end != NULL);
@@ -1486,15 +1495,23 @@ static enum test_return ascii_gets_value(const char *key, const char *value,
   char *ptr= buffer + 6 + strlen(key) + 1;
   char *end;
 
+  errno= 0;
   unsigned long val= strtoul(ptr, &end, 10); /* flags */
+  verify(errno == 0);
   verify(ptr != end);
   verify(val == 0);
   verify(end != NULL);
+
+  errno= 0;
   val= strtoul(end, &end, 10); /* size */
+  verify(errno == 0);
   verify(ptr != end);
   verify(val == datasize);
   verify(end != NULL);
+
+  errno= 0;
   *cas= strtoul(end, &end, 10); /* cas */
+  verify(errno == 0);
   verify(ptr != end);
   verify(val == datasize);
   verify(end != NULL);
index bc9a6a75140b496b1b8dd3b3489d566d23a464d5..3cee64cce518aaf3b6ca19bb64ac0b399ad6bd55 100644 (file)
@@ -47,7 +47,8 @@ int main(int argc, char *argv[])
     char *nptr;
     unsigned long value= strtoul(argv[optind], &nptr, 10);
 
-    if ((nptr == argv[optind] and value == 0) or
+    if ((errno != 0) or
+        (nptr == argv[optind] and value == 0) or
         (value == ULONG_MAX and errno == ERANGE) or
         (value == 0 and errno == EINVAL))
     {
index 67df7c7ab5bfe4fcd871a077e7c039024f4fe47b..17abff70f23049e521e7c2d7fce99058561b070c 100644 (file)
@@ -11,6 +11,7 @@
  */
 #include "mem_config.h"
 
+#include <cerrno>
 #include <cstdio>
 #include <cstring>
 #include <getopt.h>
@@ -147,7 +148,13 @@ void options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXPIRE: /* --expire */
+      errno= 0;
       opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
+      if (errno != 0)
+      {
+        std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::cerr;
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_USERNAME:
index 39b4fbe64cae7c12cd09414bd765d2b593eb6cc5..39546d4f660be95d4bf994a8c6bf731e332c802f 100644 (file)
  */
 #include "mem_config.h"
 
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
 #include <getopt.h>
+#include <unistd.h>
+
 #include <libmemcached-1.0/memcached.h>
 #include <libmemcachedutil-1.0/util.h>
 #include "client_options.h"
@@ -139,7 +141,13 @@ void options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXPIRE: /* --expire */
-      opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
+      errno= 0;
+      opt_expire= time_t(strtoll(optarg, (char **)NULL, 10));
+      if (errno != 0)
+      {
+        std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::cerr;
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_USERNAME:
index a559ef90dfcef80f1bd7cb8da62aefb5f332a257..4e4cd479e3f79599e04eec240dfe05734831ab08 100644 (file)
@@ -11,6 +11,7 @@
  */
 #include "mem_config.h"
 
+#include <cerrno>
 #include <cstdio>
 #include <cstring>
 #include <getopt.h>
@@ -204,7 +205,13 @@ static void options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXPIRE: /* --expire */
+      errno= 0;
       opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
+      if (errno != 0)
+      {
+        std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::cerr;
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_HASH:
index d32b1c040e79b6e686506dd3d06f011ae8b11c20..e66ab0fd584dbba094d675e55ef127b5083680e3 100644 (file)
@@ -39,6 +39,7 @@
 #include <mem_config.h>
 
 #include <cassert>
+#include <cerrno>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
@@ -50,7 +51,6 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
-#include <sys/types.h>
 #include <unistd.h>
 
 #include <iostream>
@@ -468,15 +468,33 @@ void options_parse(int argc, char *argv[])
       break;
 
     case OPT_SLAP_CONCURRENCY:
+      errno= 0;
       opt_concurrency= (unsigned int)strtoul(optarg, (char **)NULL, 10);
+      if (errno != 0)
+      {
+        fprintf(stderr, "Invalid value for concurrency: %s\n", optarg);
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_SLAP_EXECUTE_NUMBER:
+      errno= 0;
       opt_execute_number= (unsigned int)strtoul(optarg, (char **)NULL, 10);
+      if (errno != 0)
+      {
+        fprintf(stderr, "Invalid value for execute: %s\n", optarg);
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_SLAP_INITIAL_LOAD:
+      errno= 0;
       opt_createial_load= (unsigned int)strtoul(optarg, (char **)NULL, 10);
+      if (errno != 0)
+      {
+        fprintf(stderr, "Invalid value for initial load: %s\n", optarg);
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_QUIET:
index 73429e23c9f53b88a6a1021f9700f97eaa36fa6a..19213569c5a1a2fff23e583575bd69cd87236ef3 100644 (file)
 
 #include <mem_config.h>
 
+#include <cerrno>
 #include <cstdio>
 #include <cstring>
 #include <getopt.h>
 #include <iostream>
 #include <unistd.h>
+
 #include <libmemcached-1.0/memcached.h>
 
 #include "utilities.h"
@@ -212,7 +214,13 @@ void options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXPIRE:
+      errno= 0;
       expiration= time_t(strtoul(optarg, (char **)NULL, 10));
+      if (errno != 0)
+      {
+        fprintf(stderr, "Invalid value for --expire: %s\n", optarg);
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_QUIET:
index 2cbc7e0b384acbae901aae90c42656d969eb5981..2afc9fa10f029dc4a3b477317516a5f9ee408fff 100644 (file)
@@ -1160,7 +1160,12 @@ static int ms_ascii_process_line(ms_conn_t *c, char *command)
     {
       token_t tokens[MAX_TOKENS];
       ms_tokenize_command(command, tokens, MAX_TOKENS);
+      errno= 0;
       value_len= strtol(tokens[VALUELEN_TOKEN].value, NULL, 10);
+      if (errno != 0)
+      {
+        printf("<%d ERROR %s\n", c->sfd, strerror(errno));
+      }
       c->currcmd.key_prefix= *(uint64_t *)tokens[KEY_TOKEN].value;
 
       /*
index 3284a4f643f48a92cb7a8eca2399eb362ba31b92..7665b731b3767f7c548f8e3ffbb3a0615b00ca8d 100644 (file)
@@ -87,7 +87,13 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings)
 
       ptr++;
 
+      errno= 0;
       port= (in_port_t) strtoul(ptr, (char **)NULL, 10);
+      if (errno != 0)
+      {
+        memcached_server_free(servers);
+        return NULL;
+      }
 
       ptr2= index(ptr, ' ');
       if (! ptr2)
@@ -96,14 +102,22 @@ memcached_server_list_st memcached_servers_parse(const char *server_strings)
       if (ptr2)
       {
         ptr2++;
-        weight = (uint32_t) strtoul(ptr2, (char **)NULL, 10);
+        errno= 0;
+        weight= uint32_t(strtoul(ptr2, (char **)NULL, 10));
+        if (errno != 0)
+        {
+          memcached_server_free(servers);
+          return NULL;
+        }
       }
     }
 
     servers= memcached_server_list_append_with_weight(servers, buffer, port, weight, &rc);
 
     if (isspace(*begin_ptr))
+    {
       begin_ptr++;
+    }
   }
 
   return servers;
index 391c9309814ef10c0eb4d04c0ae0644ed4fd1f94..7503c5a0d2da58aa8764810441775b2c1c17132f 100644 (file)
@@ -90,9 +90,10 @@ static memcached_return_t textual_value_fetch(org::libmemcached::Instance* insta
   }
 
   for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++) {};
+  errno= 0;
   result->item_flags= (uint32_t) strtoul(next_ptr, &string_ptr, 10);
 
-  if (end_ptr == string_ptr)
+  if (errno != 0 or end_ptr == string_ptr)
   {
     goto read_error;
   }
@@ -105,9 +106,10 @@ static memcached_return_t textual_value_fetch(org::libmemcached::Instance* insta
   }
 
   for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++) {};
+  errno= 0;
   value_length= (size_t)strtoull(next_ptr, &string_ptr, 10);
 
-  if (end_ptr == string_ptr)
+  if (errno != 0 or end_ptr == string_ptr)
   {
     goto read_error;
   }
@@ -122,10 +124,11 @@ static memcached_return_t textual_value_fetch(org::libmemcached::Instance* insta
   {
     string_ptr++;
     for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++) {};
+    errno= 0;
     result->item_cas= strtoull(next_ptr, &string_ptr, 10);
   }
 
-  if (end_ptr < string_ptr)
+  if (errno != 0 or end_ptr < string_ptr)
   {
     goto read_error;
   }
@@ -238,8 +241,9 @@ static memcached_return_t textual_read_one_response(org::libmemcached::Instance*
         char *response_ptr= index(buffer, ' ');
 
         char *endptr;
+        errno= 0;
         long int version= strtol(response_ptr, &endptr, 10);
-        if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0)
+        if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX or version == 0)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
           return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse major version"));
@@ -247,8 +251,9 @@ static memcached_return_t textual_read_one_response(org::libmemcached::Instance*
         instance->major_version= uint8_t(version);
 
         endptr++;
+        errno= 0;
         version= strtol(endptr, &endptr, 10);
-        if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX)
+        if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
           return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse minor version"));
@@ -256,8 +261,9 @@ static memcached_return_t textual_read_one_response(org::libmemcached::Instance*
         instance->minor_version= uint8_t(version);
 
         endptr++;
+        errno= 0;
         version= strtol(endptr, &endptr, 10);
-        if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX)
+        if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
           return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version"));
@@ -442,6 +448,7 @@ static memcached_return_t textual_read_one_response(org::libmemcached::Instance*
   case '8': /* INCR/DECR response */
   case '9': /* INCR/DECR response */
     {
+      errno= 0;
       unsigned long long int auto_return_value= strtoull(buffer, (char **)NULL, 10);
 
       if (auto_return_value == ULLONG_MAX and errno == ERANGE)
@@ -456,6 +463,12 @@ static memcached_return_t textual_read_one_response(org::libmemcached::Instance*
         return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
                                    memcached_literal_param("Numeric response was out of range"));
       }
+      else if (errno != 0)
+      {
+        result->numeric_value= UINT64_MAX;
+        return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT,
+                                   memcached_literal_param("Numeric response was out of range"));
+      }
 
       result->numeric_value= uint64_t(auto_return_value);
 
@@ -620,8 +633,9 @@ static memcached_return_t binary_read_one_response(org::libmemcached::Instance*
         }
 
         char *endptr;
+        errno= 0;
         long int version= strtol(version_buffer, &endptr, 10);
-        if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX or version == 0)
+        if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX or version == 0)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
           return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse major version"));
@@ -629,8 +643,9 @@ static memcached_return_t binary_read_one_response(org::libmemcached::Instance*
         instance->major_version= uint8_t(version);
 
         endptr++;
+        errno= 0;
         version= strtol(endptr, &endptr, 10);
-        if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX)
+        if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
           return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse minor version"));
@@ -638,8 +653,9 @@ static memcached_return_t binary_read_one_response(org::libmemcached::Instance*
         instance->minor_version= uint8_t(version);
 
         endptr++;
+        errno= 0;
         version= strtol(endptr, &endptr, 10);
-        if (version == LONG_MIN or version == LONG_MAX or errno == EINVAL or version > UINT8_MAX)
+        if (errno != 0 or version == LONG_MIN or version == LONG_MAX or version > UINT8_MAX)
         {
           instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
           return memcached_set_error(*instance, MEMCACHED_UNKNOWN_READ_FAILURE, MEMCACHED_AT, memcached_literal_param("strtol() failed to parse micro version"));
index 89d5be52382bb57387c006e06ee4172ade1802e3..01a8baf6d51303799a08c3c17e656a3b72df2c26 100644 (file)
@@ -2,7 +2,7 @@
  * 
  *  Libmemcached library
  *
- *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
  *
  *  Redistribution and use in source and binary forms, with or without
  *  modification, are permitted provided that the following conditions are
@@ -91,7 +91,12 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key
   }
   else if (strcmp("pid", key) == 0)
   {
+    errno= 0;
     int64_t temp= strtoll(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
 
     if (temp <= INT32_MAX and ( sizeof(pid_t) == sizeof(int32_t) ))
     {
@@ -109,11 +114,21 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key
   }
   else if (not strcmp("uptime", key))
   {
+    errno= 0;
     memc_stat->uptime= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("time", key))
   {
+    errno= 0;
     memc_stat->time= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("version", key))
   {
@@ -122,7 +137,12 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key
   }
   else if (not strcmp("pointer_size", key))
   {
+    errno= 0;
     memc_stat->pointer_size= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("rusage_user", key))
   {
@@ -130,8 +150,20 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key
     for (walk_ptr= (char*)value; (!ispunct(*walk_ptr)); walk_ptr++) {};
     *walk_ptr= 0;
     walk_ptr++;
+
+    errno= 0;
     memc_stat->rusage_user_seconds= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
+
+    errno= 0;
     memc_stat->rusage_user_microseconds= strtoul(walk_ptr, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("rusage_system", key))
   {
@@ -139,85 +171,172 @@ static memcached_return_t set_data(memcached_stat_st *memc_stat, const char *key
     for (walk_ptr= (char*)value; (!ispunct(*walk_ptr)); walk_ptr++) {};
     *walk_ptr= 0;
     walk_ptr++;
+
+    errno= 0;
     memc_stat->rusage_system_seconds= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
+
+    errno= 0;
     memc_stat->rusage_system_microseconds= strtoul(walk_ptr, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("curr_items", key))
   {
+    errno= 0;
     memc_stat->curr_items= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("total_items", key))
   {
+    errno= 0;
     memc_stat->total_items= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("bytes_read", key))
   {
+    errno= 0;
     memc_stat->bytes_read= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("bytes_written", key))
   {
+    errno= 0;
     memc_stat->bytes_written= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("bytes", key))
   {
+    errno= 0;
     memc_stat->bytes= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("curr_connections", key))
   {
+    errno= 0;
     memc_stat->curr_connections= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("total_connections", key))
   {
+    errno= 0;
     memc_stat->total_connections= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("connection_structures", key))
   {
+    errno= 0;
     memc_stat->connection_structures= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("cmd_get", key))
   {
+    errno= 0;
     memc_stat->cmd_get= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("cmd_set", key))
   {
+    errno= 0;
     memc_stat->cmd_set= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("get_hits", key))
   {
+    errno= 0;
     memc_stat->get_hits= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("get_misses", key))
   {
+    errno= 0;
     memc_stat->get_misses= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("evictions", key))
   {
+    errno= 0;
     memc_stat->evictions= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("limit_maxbytes", key))
   {
+    errno= 0;
     memc_stat->limit_maxbytes= strtoull(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
   else if (not strcmp("threads", key))
   {
+    errno= 0;
     memc_stat->threads= strtoul(value, (char **)NULL, 10);
+    if (errno != 0)
+    {
+      return MEMCACHED_FAILURE;
+    }
   }
-  else if (not (strcmp("delete_misses", key) == 0 or /* New stats in the 1.3 beta */
-                strcmp("delete_hits", key) == 0 or /* Just swallow them for now.. */
-                strcmp("incr_misses", key) == 0 or
-                strcmp("incr_hits", key) == 0 or
-                strcmp("decr_misses", key) == 0 or
-                strcmp("decr_hits", key) == 0 or
-                strcmp("cas_misses", key) == 0 or
-                strcmp("cas_hits", key) == 0 or
-                strcmp("cas_badval", key) == 0 or
-                strcmp("cmd_flush", key) == 0 or
-                strcmp("accepting_conns", key) == 0 or
-                strcmp("listen_disabled_num", key) == 0 or
-                strcmp("conn_yields", key) == 0 or
-                strcmp("auth_cmds", key) == 0 or
-                strcmp("auth_errors", key) == 0 or
-                strcmp("reclaimed", key) == 0))
+  else if ((strcmp("delete_misses", key) == 0 or /* New stats in the 1.3 beta */
+            strcmp("delete_hits", key) == 0 or /* Just swallow them for now.. */
+            strcmp("incr_misses", key) == 0 or
+            strcmp("incr_hits", key) == 0 or
+            strcmp("decr_misses", key) == 0 or
+            strcmp("decr_hits", key) == 0 or
+            strcmp("cas_misses", key) == 0 or
+            strcmp("cas_hits", key) == 0 or
+            strcmp("cas_badval", key) == 0 or
+            strcmp("cmd_flush", key) == 0 or
+            strcmp("accepting_conns", key) == 0 or
+            strcmp("listen_disabled_num", key) == 0 or
+            strcmp("conn_yields", key) == 0 or
+            strcmp("auth_cmds", key) == 0 or
+            strcmp("auth_errors", key) == 0 or
+            strcmp("reclaimed", key) == 0) == 0)
   {
     WATCHPOINT_STRING(key);
     /* return MEMCACHED_UNKNOWN_STAT_KEY; */
index 8cd29720bae5c7c681d95eb974793a12176ec6fc..449b650d7e8e9f5b46fd2373c98b705f6b82254d 100644 (file)
@@ -561,7 +561,12 @@ static void process_arithmetic(memcached_protocol_client_st *client,
 
   uint64_t cas;
   uint64_t result;
+  errno= 0;
   uint64_t delta= strtoull(tokens[2], NULL, 10);
+  if (errno != 0)
+  {
+    return; // Error
+  }
 
   protocol_binary_response_status rval;
   if (client->ascii_command == INCR_CMD)
@@ -667,7 +672,12 @@ static void process_flush(memcached_protocol_client_st *client,
   uint32_t timeout= 0;
   if (ntokens == 2)
   {
+    errno= 0;
     timeout= (uint32_t)strtoul(tokens[1], NULL, 10);
+    if (errno != 0)
+    {
+      return; // Error
+    }
   }
 
   protocol_binary_response_status rval;
@@ -706,9 +716,30 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
     return -1;
   }
 
+  errno= 0;
   uint32_t flags= (uint32_t)strtoul(tokens[2], NULL, 10);
+  if (errno != 0)
+  {
+    /* return error */
+    raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
+    return -1;
+  }
+
   uint32_t timeout= (uint32_t)strtoul(tokens[3], NULL, 10);
+  if (errno != 0)
+  {
+    /* return error */
+    raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
+    return -1;
+  }
+
   unsigned long nbytes= strtoul(tokens[4], NULL, 10);
+  if (errno != 0)
+  {
+    /* return error */
+    raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
+    return -1;
+  }
 
   /* Do we have all data? */
   unsigned long need= nbytes + (unsigned long)((*end - start) + 1) + 2; /* \n\r\n */
@@ -743,7 +774,14 @@ static inline int process_storage_command(memcached_protocol_client_st *client,
                                                    timeout, &result_cas);
     break;
   case CAS_CMD:
+    errno= 0;
     cas= strtoull(tokens[5], NULL, 10);
+    if (errno != 0)
+    {
+      /* return error */
+      raw_response_handler(client, "CLIENT_ERROR: bad key\r\n");
+      return -1;
+    }
     /* FALLTHROUGH */
   case REPLACE_CMD:
     rval= client->root->callback->interface.v1.replace(client, key,
index 100b8e2044cc34856b986d68ce642fdf35d88d18..70aee2b00cc6336cc733fe036c54ebe7b73b103f 100644 (file)
@@ -348,7 +348,7 @@ do \
   } \
 } while (0)
 
-#define ASSERT_NEQ(__expected, __actual, ...) \
+#define ASSERT_NEQ(__expected, __actual) \
 do \
 { \
   if ((__expected) == (__actual)) { \
index fe8938b97d84919edb54d23e5a0d64de843334f5..80ffa769344d5ac89c5d72283c0c37cfa3a23b1b 100644 (file)
@@ -158,7 +158,14 @@ int main(int argc, char *argv[])
         break;
 
       case OPT_LIBYATL_REPEAT:
+        errno= 0;
         opt_repeat= strtoul(optarg, (char **) NULL, 10);
+        if (errno != 0)
+        {
+          Error << "unknown value passed to --repeat: `" << optarg << "`";
+          exit(EXIT_FAILURE);
+        }
+
         break;
 
       case OPT_LIBYATL_MATCH_COLLECTION:
@@ -186,9 +193,16 @@ int main(int argc, char *argv[])
 
   srandom((unsigned int)time(NULL));
 
-  if (bool(getenv("YATL_REPEAT")) and (strtoul(getenv("YATL_REPEAT"), (char **) NULL, 10) > 1))
+  errno= 0;
+  if (bool(getenv("YATL_REPEAT")))
   {
+    errno= 0;
     opt_repeat= strtoul(getenv("YATL_REPEAT"), (char **) NULL, 10);
+    if (errno != 0)
+    {
+      Error << "ENV YATL_REPEAT passed an invalid value: `" << getenv("YATL_REPEAT") << "`";
+      exit(EXIT_FAILURE);
+    }
   }
 
   if ((bool(getenv("YATL_QUIET")) and (strcmp(getenv("YATL_QUIET"), "0") == 0)) or opt_quiet)
index e0e1485101aaa41c9c7a8593dc379d2ff0b2feab..142f167c31398bec78d87e2272fbd43d65b93b86 100644 (file)
@@ -39,7 +39,7 @@
 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
 inline bool operator== (const memcached_st& memc, const memcached_return_t rc)
 {
-  if (memcached_last_error(const_cast<memcached_st *>(&memc)) == rc)
+  if (memcached_last_error(&memc) == rc)
   {
     return true;
   }
@@ -47,7 +47,7 @@ inline bool operator== (const memcached_st& memc, const memcached_return_t rc)
   return false;
 }
 
-inline bool operator!= (const memcached_st& memc, const memcached_return_t rc)
+inline bool operator!= (const memcached_st& memc, memcached_return_t rc)
 {
   if (memcached_last_error(const_cast<memcached_st *>(&memc)) != rc)
   {
@@ -57,7 +57,27 @@ inline bool operator!= (const memcached_st& memc, const memcached_return_t rc)
   return false;
 }
 
-inline bool operator!= (const memcached_return_t rc, const memcached_st& memc)
+inline bool operator== (memcached_st* const memc, memcached_return_t rc)
+{
+  if (memcached_last_error(memc) == rc)
+  {
+    return true;
+  }
+
+  return false;
+}
+
+inline bool operator!= (memcached_st* const memc, memcached_return_t rc)
+{
+  if (memcached_last_error(memc) != rc)
+  {
+    return true;
+  }
+
+  return false;
+}
+
+inline bool operator!= (memcached_return_t rc, const memcached_st& memc)
 {
   if (memcached_last_error(const_cast<memcached_st *>(&memc)) != rc)
   {
@@ -66,5 +86,15 @@ inline bool operator!= (const memcached_return_t rc, const memcached_st& memc)
 
   return false;
 }
+
+inline bool operator!= (memcached_return_t rc, memcached_st* const memc)
+{
+  if (memcached_last_error(memc) != rc)
+  {
+    return true;
+  }
+
+  return false;
+}
 #endif
 
index b96fea06486a311b6e00744b065dd02568c16448..c7be63fa49c90a693e7110e8911b3788fea2cfac 100644 (file)
@@ -184,11 +184,11 @@ static test_return_t test_throw_fail_TEST(void *)
 static test_return_t ASSERT_FALSE__TEST(void *)
 {
   try {
-    ASSERT_FALSE_(true, __func__);
+    ASSERT_FALSE(true);
   }
   catch (const libtest::__failure& e)
   {
-    ASSERT_STREQ(e.what(), "Assertion '!true' [ ASSERT_FALSE__TEST ]");
+    ASSERT_STREQ(e.what(), "Assertion '!true'");
     return TEST_SUCCESS;
   }
   catch (...)
@@ -199,6 +199,31 @@ static test_return_t ASSERT_FALSE__TEST(void *)
   return TEST_FAILURE;
 }
 
+static test_return_t ASSERT_NEQ_FAIL_TEST(void *)
+{
+  try {
+    ASSERT_NEQ(1,1);
+  }
+  catch (const libtest::__failure& e)
+  {
+    ASSERT_STREQ(e.what(), "Assertion '1' == '1'");
+    return TEST_SUCCESS;
+  }
+  catch (...)
+  {
+    return TEST_FAILURE;
+  }
+
+  return TEST_FAILURE;
+}
+
+static test_return_t ASSERT_NEQ_TEST(void *)
+{
+  ASSERT_NEQ(1,0);
+
+  return TEST_SUCCESS;
+}
+
 static test_return_t ASSERT_FALSE_TEST(void *)
 {
   try {
@@ -1012,6 +1037,8 @@ test_st tests_log[] ={
   {"FAIL", false, test_throw_fail_TEST },
   {"ASSERT_FALSE_", false, ASSERT_FALSE__TEST },
   {"ASSERT_FALSE", false, ASSERT_FALSE_TEST },
+  {"ASSERT_NEQ", false, ASSERT_NEQ_TEST },
+  {"ASSERT_NEQ FAIL", false, ASSERT_NEQ_FAIL_TEST },
   {0, 0, 0}
 };
 
index 643812d35a9f8529caca322bf82cb42090da8aa9..2012d477d37901901aa69665613c576dc06207ec 100644 (file)
@@ -164,6 +164,7 @@ test_st basic_tests[] ={
   {"reset stack clone", true, (test_callback_fn*)basic_reset_stack_clone_test},
   {"reset heap clone", true, (test_callback_fn*)basic_reset_heap_clone_test},
   {"memcached_return_t", false, (test_callback_fn*)memcached_return_t_TEST },
+  {"c++ memcached_st == memcached_return_t", false, (test_callback_fn*)comparison_operator_memcached_st_and__memcached_return_t_TEST },
   {0, 0, 0}
 };
 
index 4241220ae41a2d7846f75fca55e8183a6a9316eb..f26f7c4cb4367982603065d02d127bd22eaac42a 100644 (file)
@@ -2813,6 +2813,20 @@ test_return_t user_supplied_bug21(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
+test_return_t comparison_operator_memcached_st_and__memcached_return_t_TEST(memcached_st *)
+{
+  test::Memc memc_;
+
+  memcached_st *memc= &memc_;
+
+  ASSERT_EQ(memc, MEMCACHED_SUCCESS);
+  test_compare(memc, MEMCACHED_SUCCESS);
+
+  ASSERT_NEQ(memc, MEMCACHED_FAILURE);
+
+  return TEST_SUCCESS;
+}
+
 test_return_t ketama_TEST(memcached_st *)
 {
   test::Memc memc("--server=10.0.1.1:11211 --server=10.0.1.2:11211");
@@ -4666,7 +4680,7 @@ test_return_t regression_bug_583031(memcached_st *)
   test_false(value);
   test_zero(length);
 
-  test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_error(memc));
+  test_compare(MEMCACHED_TIMEOUT, memc);
 
   memcached_free(memc);
 
@@ -5001,7 +5015,8 @@ test_return_t kill_HUP_TEST(memcached_st *original_memc)
                                         test_literal_param(__func__), // Keys
                                         test_literal_param(__func__), // Values
                                         0, 0);
-  test_compare(ret, MEMCACHED_CONNECTION_FAILURE);
+  test_compare(ret, memc);
+  test_compare(MEMCACHED_CONNECTION_FAILURE, memc);
 
   memcached_free(memc);
 
index 0ecea0d2d54e6362117818036268d8743efae004..9edc820ec1ae197b466b4480d3d67d89427dc938 100644 (file)
@@ -184,3 +184,4 @@ test_return_t regression_994772_TEST(memcached_st*);
 test_return_t regression_1009493_TEST(memcached_st*);
 test_return_t regression_1048945_TEST(memcached_st*);
 test_return_t regression_1067242_TEST(memcached_st*);
+test_return_t comparison_operator_memcached_st_and__memcached_return_t_TEST(memcached_st*);