LP#1652382: more improvements to cache key munging
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 15 Feb 2017 21:58:06 +0000 (16:58 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 16 Feb 2017 19:54:34 +0000 (14:54 -0500)
- teach osrfCacheRemove to clean keys
- fix implict declaration compilation warning
- account for fact that iscntrl('\0') returns true

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>

src/libopensrf/osrf_cache.c

index dd489e1..2f829cc 100644 (file)
@@ -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));