[OpenSRF-GIT] OpenSRF branch master updated. cbd252babff1d7c9c92db8d2b46f6172eb9a3845

Evergreen Git git at git.evergreen-ils.org
Thu Feb 16 16:54:52 EST 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenSRF".

The branch, master has been updated
       via  cbd252babff1d7c9c92db8d2b46f6172eb9a3845 (commit)
       via  7524221ddbcdc2fd7780501f3fdf36ecc2e41cb0 (commit)
       via  3277648c61f53ed8e36b9d51404d2b1979182c33 (commit)
       via  dbc54c646055d8840140eca7d2a1fa0760537688 (commit)
      from  e71d790a92f497e5bc983c4ba970168129fbcdd3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cbd252babff1d7c9c92db8d2b46f6172eb9a3845
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Wed Feb 15 16:58:06 2017 -0500

    LP#1652382: more improvements to cache key munging
    
    - teach osrfCacheRemove to clean keys
    - fix implict declaration compilation warning
    - account for fact that iscntrl('\0') returns true
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Jeff Davis <jdavis at sitka.bclibraries.ca>

diff --git a/src/libopensrf/osrf_cache.c b/src/libopensrf/osrf_cache.c
index dd489e1..2f829cc 100644
--- a/src/libopensrf/osrf_cache.c
+++ b/src/libopensrf/osrf_cache.c
@@ -14,6 +14,7 @@ GNU General Public License for more details.
 */
 
 #include <opensrf/osrf_cache.h>
+#include <ctype.h>
 
 #define MAX_KEY_LEN 250
 
@@ -59,7 +60,7 @@ char* _clean_key( const char* key ) {
     char* clean_key = (char*)strdup(key);
     char* d = clean_key;
     char* s = clean_key;
-    do while(isspace(*s) || iscntrl(*s)) s++; while(*d++ = *s++);
+    do while(isspace(*s) || ((*s != '\0') && iscntrl(*s))) s++; while(*d++ = *s++);
     if (strlen(clean_key) > MAX_KEY_LEN) {
         char *hashed = md5sum(clean_key);
         clean_key[0] = '\0';
@@ -138,7 +139,9 @@ int osrfCacheRemove( const char* key, ... ) {
 	memcached_return rc;
 	if( key ) {
 		VA_LIST_TO_STRING(key);
-		rc = memcached_delete(_osrfCache, VA_BUF, strlen(VA_BUF), 0 );
+		char* clean_key = _clean_key( VA_BUF );
+		rc = memcached_delete(_osrfCache, clean_key, strlen(clean_key), 0 );
+		free(clean_key);
 		if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED) {
 			osrfLogDebug(OSRF_LOG_MARK, "Failed to delete key [%s] - %s",
 				VA_BUF, memcached_strerror(_osrfCache, rc));

commit 7524221ddbcdc2fd7780501f3fdf36ecc2e41cb0
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Wed Feb 15 14:12:34 2017 -0500

    LP#1652382: handle cases where supplied key is longer than 250 bytes
    
    With this patch, if cache clients want to use a key longer
    than the memcached text protocol limit of 250 bytes, the
    key is normalized to 'shortened_' + md5_hex(normalized_key).
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Jeff Davis <jdavis at sitka.bclibraries.ca>

diff --git a/src/libopensrf/osrf_cache.c b/src/libopensrf/osrf_cache.c
index 4fccfd0..dd489e1 100644
--- a/src/libopensrf/osrf_cache.c
+++ b/src/libopensrf/osrf_cache.c
@@ -15,6 +15,8 @@ GNU General Public License for more details.
 
 #include <opensrf/osrf_cache.h>
 
+#define MAX_KEY_LEN 250
+
 static struct memcached_st* _osrfCache = NULL;
 static time_t _osrfCacheMaxSeconds = -1;
 static char* _clean_key( const char* );
@@ -57,7 +59,14 @@ char* _clean_key( const char* key ) {
     char* clean_key = (char*)strdup(key);
     char* d = clean_key;
     char* s = clean_key;
-    do while(isspace(*s)) s++; while(*d++ = *s++);
+    do while(isspace(*s) || iscntrl(*s)) s++; while(*d++ = *s++);
+    if (strlen(clean_key) > MAX_KEY_LEN) {
+        char *hashed = md5sum(clean_key);
+        clean_key[0] = '\0';
+        strncat(clean_key, "shortened_", 11);
+        strncat(clean_key, hashed, MAX_KEY_LEN);
+        free(hashed);
+    }
     return clean_key;
 }
 
diff --git a/src/perl/lib/OpenSRF/Utils/Cache.pm b/src/perl/lib/OpenSRF/Utils/Cache.pm
index ba9f1a1..36721d9 100644
--- a/src/perl/lib/OpenSRF/Utils/Cache.pm
+++ b/src/perl/lib/OpenSRF/Utils/Cache.pm
@@ -2,6 +2,7 @@ package OpenSRF::Utils::Cache;
 use strict; use warnings;
 use base qw/OpenSRF/;
 use Cache::Memcached;
+use Digest::MD5 qw(md5_hex);
 use OpenSRF::Utils::Logger qw/:level/;
 use OpenSRF::Utils::Config;
 use OpenSRF::Utils::SettingsClient;
@@ -281,6 +282,9 @@ sub _clean_cache_key {
     my $key = shift;
 
     $key =~ s{(\p{Cntrl}|\s)}{}g;
+    if (length($key) > 250) { # max length of memcahed key
+        $key = 'shortened_' . md5_hex($key);
+    }
 
     return $key;
 }

commit 3277648c61f53ed8e36b9d51404d2b1979182c33
Author: Mike Rylander <mrylander at gmail.com>
Date:   Mon Jan 30 12:54:10 2017 -0500

    LP#1652382: Make use of the clean key just created
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Jeff Davis <jdavis at sitka.bclibraries.ca>

diff --git a/src/libopensrf/osrf_cache.c b/src/libopensrf/osrf_cache.c
index 7574b95..4fccfd0 100644
--- a/src/libopensrf/osrf_cache.c
+++ b/src/libopensrf/osrf_cache.c
@@ -111,7 +111,7 @@ char* osrfCacheGetString( const char* key, ... ) {
 	if( key ) {
 		VA_LIST_TO_STRING(key);
 		char* clean_key = _clean_key( VA_BUF );
-		char* data = (char*) memcached_get(_osrfCache, VA_BUF, strlen(VA_BUF), &val_len, &flags, &rc);
+		char* data = (char*) memcached_get(_osrfCache, clean_key, strlen(clean_key), &val_len, &flags, &rc);
 		free(clean_key);
 		if (rc != MEMCACHED_SUCCESS) {
 			osrfLogDebug(OSRF_LOG_MARK, "Failed to get key [%s] - %s",

commit dbc54c646055d8840140eca7d2a1fa0760537688
Author: Mike Rylander <mrylander at gmail.com>
Date:   Fri Jan 27 15:25:05 2017 -0500

    LP#1652382: normalization of memcache keys in C code
    
    Memcache does not allow spaces in keys, so here we will actively strip them
    from any key we get from a caller.  Some callers are not very proactive about
    sending clean keys, and this patch prevents issues that can poison C-based
    OpenSRF service backends.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Jeff Davis <jdavis at sitka.bclibraries.ca>

diff --git a/src/libopensrf/osrf_cache.c b/src/libopensrf/osrf_cache.c
index fc4d488..7574b95 100644
--- a/src/libopensrf/osrf_cache.c
+++ b/src/libopensrf/osrf_cache.c
@@ -17,6 +17,7 @@ GNU General Public License for more details.
 
 static struct memcached_st* _osrfCache = NULL;
 static time_t _osrfCacheMaxSeconds = -1;
+static char* _clean_key( const char* );
 
 int osrfCacheInit( const char* serverStrings[], int size, time_t maxCacheSeconds ) {
 	memcached_server_st *server_pool;
@@ -52,17 +53,30 @@ int osrfCachePutObject( const char* key, const jsonObject* obj, time_t seconds )
 	return 0;
 }
 
+char* _clean_key( const char* key ) {
+    char* clean_key = (char*)strdup(key);
+    char* d = clean_key;
+    char* s = clean_key;
+    do while(isspace(*s)) s++; while(*d++ = *s++);
+    return clean_key;
+}
+
 int osrfCachePutString( const char* key, const char* value, time_t seconds ) {
 	memcached_return rc;
 	if( !(key && value) ) return -1;
 	seconds = (seconds <= 0 || seconds > _osrfCacheMaxSeconds) ? _osrfCacheMaxSeconds : seconds;
 	osrfLogInternal( OSRF_LOG_MARK, "osrfCachePutString(): Putting string (key=%s): %s", key, value);
+
+	char* clean_key = _clean_key( key );
+
 	/* add or overwrite existing key:value pair */
-	rc = memcached_set(_osrfCache, key, strlen(key), value, strlen(value), seconds, 0);
+	rc = memcached_set(_osrfCache, clean_key, strlen(clean_key), value, strlen(value), seconds, 0);
 	if (rc != MEMCACHED_SUCCESS) {
 		osrfLogError(OSRF_LOG_MARK, "Failed to cache key:value [%s]:[%s] - %s",
 			key, value, memcached_strerror(_osrfCache, rc));
 	}
+
+	free(clean_key);
 	return 0;
 }
 
@@ -73,7 +87,9 @@ jsonObject* osrfCacheGetObject( const char* key, ... ) {
 	jsonObject* obj = NULL;
 	if( key ) {
 		VA_LIST_TO_STRING(key);
-		const char* data = (const char*) memcached_get(_osrfCache, VA_BUF, strlen(VA_BUF), &val_len, &flags, &rc);
+		char* clean_key = _clean_key( VA_BUF );
+		const char* data = (const char*) memcached_get(_osrfCache, clean_key, strlen(clean_key), &val_len, &flags, &rc);
+		free(clean_key);
 		if (rc != MEMCACHED_SUCCESS) {
 			osrfLogDebug(OSRF_LOG_MARK, "Failed to get key [%s] - %s",
 				VA_BUF, memcached_strerror(_osrfCache, rc));
@@ -94,7 +110,9 @@ char* osrfCacheGetString( const char* key, ... ) {
 	memcached_return rc;
 	if( key ) {
 		VA_LIST_TO_STRING(key);
+		char* clean_key = _clean_key( VA_BUF );
 		char* data = (char*) memcached_get(_osrfCache, VA_BUF, strlen(VA_BUF), &val_len, &flags, &rc);
+		free(clean_key);
 		if (rc != MEMCACHED_SUCCESS) {
 			osrfLogDebug(OSRF_LOG_MARK, "Failed to get key [%s] - %s",
 				VA_BUF, memcached_strerror(_osrfCache, rc));

-----------------------------------------------------------------------

Summary of changes:
 src/libopensrf/osrf_cache.c         |   38 +++++++++++++++++++++++++++++++---
 src/perl/lib/OpenSRF/Utils/Cache.pm |    4 +++
 2 files changed, 38 insertions(+), 4 deletions(-)


hooks/post-receive
-- 
OpenSRF


More information about the opensrf-commits mailing list