From 4744d1a42b709a2c7aa778565c0c32a1962e0e2c Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 15 Feb 2017 16:58:06 -0500 Subject: [PATCH] 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 Signed-off-by: Jeff Davis --- src/libopensrf/osrf_cache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 +#include #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)); -- 2.43.2