From 74d399ab8188cbec655c5833f77977b49d4bcae5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Tue, 27 Aug 2013 09:56:50 +0900 Subject: [PATCH] evas/cserve2: Fix NULL vs. empty string Server side: Some strings were NULL, some other were empty. Client side was looking for NULL, but the shared index contained empty key. --- src/bin/evas/evas_cserve2_cache.c | 32 ++++++++++++++++++++------------ src/bin/evas/evas_cserve2_index.c | 10 +++++----- src/bin/evas/evas_cserve2_main.c | 7 ++++--- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/bin/evas/evas_cserve2_cache.c b/src/bin/evas/evas_cserve2_cache.c index bc89150..f351dd7 100644 --- a/src/bin/evas/evas_cserve2_cache.c +++ b/src/bin/evas/evas_cserve2_cache.c @@ -197,7 +197,6 @@ _entry_load_reused(Entry *e) #endif } - static int _shm_object_id_cmp_cb(const void *data1, const void *data2) { @@ -545,7 +544,7 @@ _font_loaded_send(Client *client, unsigned int rid) static void * _open_request_build(Entry *entry, int *bufsize) { - const char *loader_data; + const char *loader_data, *key, *path; char *buf; int size, pathlen, keylen, loaderlen; Slave_Msg_Image_Open msg; @@ -561,8 +560,12 @@ _open_request_build(Entry *entry, int *bufsize) return NULL; } - pathlen = strlen(cserve2_shared_string_get(fd->path)) + 1; - keylen = strlen(cserve2_shared_string_get(fd->key)) + 1; + path = cserve2_shared_string_get(fd->path); + key = cserve2_shared_string_get(fd->key); + if (!path) path = ""; + if (!key) key = ""; + pathlen = strlen(path) + 1; + keylen = strlen(key) + 1; memset(&msg, 0, sizeof(msg)); loader_data = cserve2_shared_string_get(fd->loader_data); @@ -574,8 +577,8 @@ _open_request_build(Entry *entry, int *bufsize) if (!buf) return NULL; memcpy(buf, &msg, sizeof(msg)); - memcpy(buf + sizeof(msg), cserve2_shared_string_get(fd->path), pathlen); - memcpy(buf + sizeof(msg) + pathlen, cserve2_shared_string_get(fd->key), keylen); + memcpy(buf + sizeof(msg), path, pathlen); + memcpy(buf + sizeof(msg) + pathlen, key, keylen); if (msg.has_loader_data) memcpy(buf + sizeof(msg) + pathlen + keylen, loader_data, loaderlen); @@ -661,7 +664,7 @@ static void * _load_request_build(Image_Entry *ientry, int *bufsize) { char *buf, *ptr; - const char *shmpath, *loader_data; + const char *shmpath, *loader_data, *path, *key; int size; int shmlen, filelen, keylen, loaderlen; Slave_Msg_Image_Load msg; @@ -686,8 +689,12 @@ _load_request_build(Image_Entry *ientry, int *bufsize) shmpath = cserve2_shm_name_get(ientry->shm); shmlen = strlen(shmpath) + 1; - filelen = strlen(cserve2_shared_string_get(fd->path)) + 1; - keylen = strlen(cserve2_shared_string_get(fd->key)) + 1; + path = cserve2_shared_string_get(fd->path); + key = cserve2_shared_string_get(fd->key); + if (!path) path = ""; + if (!key) key = ""; + filelen = strlen(path) + 1; + keylen = strlen(key) + 1; loader_data = cserve2_shared_string_get(fd->loader_data); if (loader_data) loaderlen = strlen(loader_data) + 1; @@ -724,11 +731,12 @@ _load_request_build(Image_Entry *ientry, int *bufsize) memcpy(ptr, shmpath, shmlen); ptr += shmlen; - memcpy(ptr, cserve2_shared_string_get(fd->path), filelen); + memcpy(ptr, path, filelen); ptr += filelen; - memcpy(ptr, cserve2_shared_string_get(fd->key), keylen); + memcpy(ptr, key, keylen); ptr += keylen; - if (loaderlen > 0) memcpy(ptr, cserve2_shared_string_get(fd->loader_data), loaderlen); + if (loaderlen > 0) + memcpy(ptr, loader_data, loaderlen); *bufsize = size; diff --git a/src/bin/evas/evas_cserve2_index.c b/src/bin/evas/evas_cserve2_index.c index 816a686..fdff6b5 100644 --- a/src/bin/evas/evas_cserve2_index.c +++ b/src/bin/evas/evas_cserve2_index.c @@ -921,7 +921,7 @@ cserve2_shared_string_add(const char *str) char *data; int len, id; - if (!str) return -1; + if (!str) return 0; // Find in known strings id = (int) (intptr_t) eina_hash_find(_string_entries, str); @@ -945,7 +945,7 @@ new_entry: if (!ie) { ERR("Could not store new string in shm"); - return -1; + return 0; } data = _string_mempool->ds->data + ie->offset; @@ -957,7 +957,7 @@ new_entry: int cserve2_shared_string_ref(int id) { - if (!id) return 0; + if (id <= 0) return 0; return cserve2_shared_mempool_buffer_ref(_string_mempool, id); } @@ -966,7 +966,7 @@ cserve2_shared_string_del(int id) { const char *data; - if (!id) return; + if (id <= 0) return; if ((data = _shared_mempool_buffer_del(_string_mempool, id)) != NULL) { if (!eina_hash_del_by_key(_string_entries, data)) @@ -980,7 +980,7 @@ cserve2_shared_string_del(int id) const char * cserve2_shared_string_get(int id) { - if (!id) return NULL; + if (id <= 0) return NULL; return cserve2_shared_mempool_buffer_get(_string_mempool, id); } diff --git a/src/bin/evas/evas_cserve2_main.c b/src/bin/evas/evas_cserve2_main.c index fa70fec..90a811a 100644 --- a/src/bin/evas/evas_cserve2_main.c +++ b/src/bin/evas/evas_cserve2_main.c @@ -135,15 +135,17 @@ static void _cserve2_client_open(Client *client) { Msg_Open *msg = (Msg_Open *)client->msg.buf; - const char *path, *key; + const char *path, *key, *end; path = ((const char *)msg) + sizeof(*msg) + msg->path_offset; key = ((const char *)msg) + sizeof(*msg) + msg->key_offset; + end = key + strlen(key) + 1; INF("Received OPEN command: RID=%d", msg->base.rid); INF("File_ID: %d, path=\"%s\", key=\"%s\", has_load_opts=%d", msg->file_id, path, key, (int) msg->has_load_opts); + if (!key[0]) key = NULL; cserve2_cache_file_open(client, msg->file_id, path, key, msg->base.rid); if (!msg->has_load_opts) @@ -152,8 +154,7 @@ _cserve2_client_open(Client *client) else { // FIXME: Check message size first? - Evas_Image_Load_Opts *opts = - (Evas_Image_Load_Opts*) (key + strlen(key) + 1); + Evas_Image_Load_Opts *opts = (Evas_Image_Load_Opts *) end; DBG("Load Options:"); DBG("\tdpi: %03.1f", opts->dpi); -- 2.7.4