comparison src/c/urweb.c @ 2297:6d56080f495c

Fix a read-after-free bug using a timestamp check
author Adam Chlipala <adam@chlipala.net>
date Thu, 19 Nov 2015 13:18:58 -0500
parents 5104e480b3e3
children 6e580e319077
comparison
equal deleted inserted replaced
2296:5104e480b3e3 2297:6d56080f495c
4718 uw_Sqlcache_add(cache, entry, len); 4718 uw_Sqlcache_add(cache, entry, len);
4719 } 4719 }
4720 } 4720 }
4721 free(key); 4721 free(key);
4722 } 4722 }
4723 uw_Sqlcache_freeValue(entry->value); 4723 if (entry->value && entry->value->timeValid < value->timeValid) {
4724 entry->value = value; 4724 uw_Sqlcache_freeValue(entry->value);
4725 entry->value->timeValid = timeNow; 4725 entry->value = value;
4726 entry->value->timeValid = timeNow;
4727 }
4726 pthread_rwlock_unlock(&cache->lockIn); 4728 pthread_rwlock_unlock(&cache->lockIn);
4727 } 4729 }
4728 4730
4729 static void uw_Sqlcache_flushCommitOne(uw_Sqlcache_Cache *cache, char **keys) { 4731 static void uw_Sqlcache_flushCommitOne(uw_Sqlcache_Cache *cache, char **keys) {
4730 } 4732 }
4805 uw_Sqlcache_Update *update = malloc(sizeof(uw_Sqlcache_Update)); 4807 uw_Sqlcache_Update *update = malloc(sizeof(uw_Sqlcache_Update));
4806 update->cache = cache; 4808 update->cache = cache;
4807 update->keys = uw_Sqlcache_copyKeys(keys, cache->numKeys); 4809 update->keys = uw_Sqlcache_copyKeys(keys, cache->numKeys);
4808 update->value = value; 4810 update->value = value;
4809 update->next = NULL; 4811 update->next = NULL;
4812 value->timeValid = uw_Sqlcache_getTimeNow(cache);
4810 if (ctx->cacheUpdateTail) { 4813 if (ctx->cacheUpdateTail) {
4811 ctx->cacheUpdateTail->next = update; 4814 ctx->cacheUpdateTail->next = update;
4812 } else { 4815 } else {
4813 ctx->cacheUpdate = update; 4816 ctx->cacheUpdate = update;
4814 } 4817 }