Merge pull request #124 from adsr/underflow-fix
authorMichael Wallner <mike@php.net>
Wed, 9 Nov 2022 10:58:43 +0000 (11:58 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Nov 2022 10:58:43 +0000 (11:58 +0100)
Prevent underflow in `memcached_*_response_decrement` macros

.builds/freebsd.yml
CMake/CheckThreads.cmake
CMakeVersions.txt
ChangeLog-1.1.md
docs/source/ChangeLog-1.1.rst
src/libmemcached/flush.cc
src/libmemcached/storage.cc
src/libmemcached/touch.cc
test/lib/common.hpp
test/tests/memcached/regression/gh_0125.cpp [new file with mode: 0644]

index cfb3585bef3d82c9b2bd1f5a6dc4039560827e61..2b4fda957e29f829f0b08601d434a1e046b262e9 100644 (file)
@@ -8,8 +8,8 @@ packages:
   - flex
   - libevent
   - pkgconf
-  - py38-sphinx
-  - py38-m2r
+  - py39-sphinx
+  - py39-m2r
   - rsync
   - tbb
 sources:
@@ -33,7 +33,7 @@ tasks:
       cd memcached
       echo bin/memcached > pkg-plist
       maybe make all install PREFIX=/home/build \
-        INSTALL_AS_USER=1 NO_PKG_REGISTER=1 \
+        INSTALL_AS_USER=1 NO_PKG_REGISTER=1 PKG_REGISTER=/usr/bin/true \
         SASLPWDB_CONFIGURE_ENABLE=sasl-pwdb \
         OPTIONS_SET="SASL SASLPWDB" \
         OPTIONS_DEFINE="SASL SASLPWDB"
index ab746248be3130481c05ec54ff3217545a629dc0..e4f53c2b8f83ed5dc680bd15bf543a3928a04e67 100644 (file)
@@ -1,5 +1,9 @@
-configure_define(HAVE_PTHREAD_H)
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 set(CMAKE_THREAD_PREFER_PTHREAD ON)
 find_package(Threads)
-set(HAVE_PTHREAD_H ${CMAKE_HAVE_PTHREAD_H} CACHE INTERNAL "FindThreads found pthread.h")
+if(CMAKE_HAVE_PTHREAD_H)
+    configure_define(HAVE_PTHREAD_H)
+    set(HAVE_PTHREAD_H ${CMAKE_HAVE_PTHREAD_H} CACHE INTERNAL "FindThreads found pthread.h")
+elseif(CMAKE_USE_PTHREADS_INIT)
+    check_cxx_include(pthread.h)
+endif()
index 2e2491c2672f2ee8ee801f49646807c4cfaf6bb1..fb01e29443ddb00af3350e7242b5abde535672cf 100644 (file)
@@ -2,9 +2,9 @@
 # libmemcached
 #
 
-set(LIBMEMCACHED_VERSION 1.1.1)
+set(LIBMEMCACHED_VERSION 1.1.2)
 set(LIBMEMCACHED_VERSION_INC 1.0)
-set(LIBMEMCACHED_VERSION_HEX 0x001001001)
+set(LIBMEMCACHED_VERSION_HEX 0x001001002)
 
 # libmemcached.so
 
index 9546980e7a5f0fde19f41fec338721bcc90ccb9c..95eb157b75e64191101e34f688794e89ea1625ca 100644 (file)
@@ -1,5 +1,18 @@
 # ChangeLog v1.1
 
+## v 1.1.2
+
+> released 2022-08-10
+
+* Fix handling of negative expiration values, which are somehow allowed by legacy.  
+  See also [gh #125](https://github.com/awesomized/libmemcached/issues/125),
+  and [gh #76](https://github.com/awesomized/libmemcached/issues/76).
+* Fix [gh #122](https://github.com/awesomized/libmemcached/issues/122):
+  If libcrypto implementation of AES is used, do not compile internal.
+* Fix missing include of <array> in tests.
+* Fix warnings with non-SASL builds.
+* Fix pthread.h detection.
+
 ## v 1.1.1
 
 > released 2021-09-16
index 635e06199ce06da285d2d30db4dbb89b5b6da173..1895806f40e2efdce8e9d1498aaa1e449acf6675 100644 (file)
@@ -5,6 +5,24 @@
 ChangeLog v1.1
 ==============
 
+v 1.1.2
+-------
+
+..
+
+   released 2022-08-10
+
+
+
+* Fix handling of negative expiration values, which are somehow allowed by legacy.\ :raw-html-m2r:`<br>`
+  See also `gh #125 <https://github.com/awesomized/libmemcached/issues/125>`_\ ,
+  and `gh #76 <https://github.com/awesomized/libmemcached/issues/76>`_.
+* Fix `gh #122 <https://github.com/awesomized/libmemcached/issues/122>`_\ :
+  If libcrypto implementation of AES is used, do not compile internal.
+* Fix missing include of :raw-html-m2r:`<array>` in tests.
+* Fix warnings with non-SASL builds.
+* Fix pthread.h detection.
+
 v 1.1.1
 -------
 
index 5e358b0863ea7aa6271f521ed7072db0e1b88413..e0b45b68adf56c0d59f1a4aa9b3d71b18c68d7bb 100644 (file)
@@ -61,10 +61,10 @@ static memcached_return_t memcached_flush_binary(Memcached *ptr, time_t expirati
 
 static memcached_return_t memcached_flush_textual(Memcached *ptr, time_t expiration,
                                                   const bool reply) {
-  char buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1];
+  char buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1 + 1];
   int send_length = 0;
   if (expiration) {
-    send_length = snprintf(buffer, sizeof(buffer), "%llu", (unsigned long long) expiration);
+    send_length = snprintf(buffer, sizeof(buffer), "%lld", (long long) expiration);
   }
 
   if (size_t(send_length) >= sizeof(buffer) or send_length < 0) {
index 8e6d5377aa5041721a8e69fb519401ad0c837826..31eadb1e2e9fa9aa8416a18ee673014f6c421854 100644 (file)
@@ -42,7 +42,7 @@ static inline const char *storage_op_string(memcached_storage_action_t verb) {
   return "set ";
 }
 
-static inline bool can_by_encrypted(const memcached_storage_action_t verb) {
+static inline bool can_be_encrypted(const memcached_storage_action_t verb) {
   switch (verb) {
   case SET_OP:
   case ADD_OP:
@@ -189,9 +189,9 @@ memcached_send_ascii(Memcached *ptr, memcached_instance_st *instance, const char
         memcached_literal_param("snprintf(MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH)"));
   }
 
-  char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1];
-  int expiration_buffer_length = snprintf(expiration_buffer, sizeof(expiration_buffer), " %llu",
-                                          (unsigned long long) expiration);
+  char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1 + 1];
+  int expiration_buffer_length = snprintf(expiration_buffer, sizeof(expiration_buffer), " %lld",
+                                          (long long) expiration);
   if (size_t(expiration_buffer_length) >= sizeof(expiration_buffer) or expiration_buffer_length < 0)
   {
     return memcached_set_error(
@@ -296,7 +296,7 @@ memcached_send(memcached_st *shell, const char *group_key, size_t group_key_leng
   hashkit_string_st *destination = NULL;
 
   if (memcached_is_encrypted(ptr)) {
-    if (can_by_encrypted(verb) == false) {
+    if (can_be_encrypted(verb) == false) {
       return memcached_set_error(
           *ptr, MEMCACHED_NOT_SUPPORTED, MEMCACHED_AT,
           memcached_literal_param("Operation not allowed while encyrption is enabled"));
index 6d8fdc4efd4e63b838a743359e36088b4414c4cf..b55f33e0e032e59a15651f2f6595d83146b7b89f 100644 (file)
@@ -17,9 +17,9 @@
 
 static memcached_return_t ascii_touch(memcached_instance_st *instance, const char *key,
                                       size_t key_length, time_t expiration) {
-  char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1];
-  int expiration_buffer_length = snprintf(expiration_buffer, sizeof(expiration_buffer), " %llu",
-                                          (unsigned long long) expiration);
+  char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1 + 1];
+  int expiration_buffer_length = snprintf(expiration_buffer, sizeof(expiration_buffer), " %lld",
+                                          (long long) expiration);
   if (size_t(expiration_buffer_length) >= sizeof(expiration_buffer) + 1
       or expiration_buffer_length < 0)
   {
index 083efe0d66f060eaa2f4dd2baa2e7de7efc6659a..68e9fa329cbb69abdd03f115d42b463c31dce1ce 100644 (file)
@@ -15,6 +15,7 @@
 
 #pragma once
 
+#include <array>
 #include <chrono>
 #include <cstring>
 #include <iostream>
diff --git a/test/tests/memcached/regression/gh_0125.cpp b/test/tests/memcached/regression/gh_0125.cpp
new file mode 100644 (file)
index 0000000..ca04af2
--- /dev/null
@@ -0,0 +1,15 @@
+#include "test/lib/common.hpp"
+#include "test/lib/MemcachedCluster.hpp"
+
+TEST_CASE("memcached_regression_gh_0125") {
+  auto test = MemcachedCluster::network();
+  auto memc = &test.memc;
+  auto blob = random_ascii_string(1024);
+  auto binary = GENERATE(0, 1);
+
+  test.enableBinaryProto(binary);
+  INFO("binary: " << binary);
+
+  memcached_return_t rc = memcached_set(memc, S("key"), blob.c_str(), blob.length(), -123, 0);
+  REQUIRE_SUCCESS(rc);
+}