LP#1702978: memcache Get methods use key as va_list format
authorMike Rylander <mrylander@gmail.com>
Fri, 7 Jul 2017 19:22:21 +0000 (15:22 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 10 Aug 2018 12:08:47 +0000 (08:08 -0400)
And, when a key (composed of, say, a username or barcode) has a % in it,
bad things happen.  We will stop acting as if these are variadic functions
now, and also update Evergreen so that it does not do that either.

TODO: Make these actually non-variadic, but that breaks ABI.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Cesar Velez <cesar.velez@equinoxinitiative.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>

src/libopensrf/osrf_cache.c

index 08ac596..b6e9f1b 100644 (file)
@@ -98,20 +98,19 @@ jsonObject* osrfCacheGetObject( const char* key, ... ) {
        memcached_return rc;
        jsonObject* obj = NULL;
        if( key ) {
-               VA_LIST_TO_STRING(key);
-               char* clean_key = _clean_key( VA_BUF );
+               char* clean_key = _clean_key( key );
                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));
+                               key, memcached_strerror(_osrfCache, rc));
                }
                if( data ) {
-                       osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object (key=%s): %s", VA_BUF, data);
+                       osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetObject(): Returning object (key=%s): %s", key, data);
                        obj = jsonParse( data );
                        return obj;
                }
-               osrfLogDebug(OSRF_LOG_MARK, "No cache data exists with key %s", VA_BUF);
+               osrfLogDebug(OSRF_LOG_MARK, "No cache data exists with key %s", key);
        }
        return NULL;
 }
@@ -121,16 +120,15 @@ char* osrfCacheGetString( const char* key, ... ) {
        uint32_t flags;
        memcached_return rc;
        if( key ) {
-               VA_LIST_TO_STRING(key);
-               char* clean_key = _clean_key( VA_BUF );
+               char* clean_key = _clean_key( key );
                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",
-                               VA_BUF, memcached_strerror(_osrfCache, rc));
+                               key, memcached_strerror(_osrfCache, rc));
                }
-               osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetString(): Returning object (key=%s): %s", VA_BUF, data);
-               if(!data) osrfLogDebug(OSRF_LOG_MARK, "No cache data exists with key %s", VA_BUF);
+               osrfLogInternal( OSRF_LOG_MARK, "osrfCacheGetString(): Returning object (key=%s): %s", key, data);
+               if(!data) osrfLogDebug(OSRF_LOG_MARK, "No cache data exists with key %s", key);
                return data;
        }
        return NULL;
@@ -140,13 +138,12 @@ char* osrfCacheGetString( const char* key, ... ) {
 int osrfCacheRemove( const char* key, ... ) {
        memcached_return rc;
        if( key ) {
-               VA_LIST_TO_STRING(key);
-               char* clean_key = _clean_key( VA_BUF );
+               char* clean_key = _clean_key( key );
                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));
+                               key, memcached_strerror(_osrfCache, rc));
                }
                return 0;
        }
@@ -156,10 +153,9 @@ int osrfCacheRemove( const char* key, ... ) {
 
 int osrfCacheSetExpire( time_t seconds, const char* key, ... ) {
        if( key ) {
-               VA_LIST_TO_STRING(key);
-               jsonObject* o = osrfCacheGetObject( VA_BUF );
-               //osrfCacheRemove(VA_BUF);
-               int rc = osrfCachePutObject( VA_BUF, o, seconds );
+               char* clean_key = _clean_key( key );
+               jsonObject* o = osrfCacheGetObject( clean_key );
+               int rc = osrfCachePutObject( clean_key, o, seconds );
                jsonObjectFree(o);
                return rc;
        }