From: Jean-Philippe Andre Date: Thu, 8 Dec 2016 06:49:03 +0000 (+0900) Subject: eina: Reinstall magic checks on Eina_File X-Git-Tag: upstream/1.20.0~3000 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=208e152bafca9165d3dfccb99d96a4308a663ade;p=platform%2Fupstream%2Fefl.git eina: Reinstall magic checks on Eina_File file != NULL does not mean it's valid. Since Eina_File is a basic eina type a magic check is still better than nothing. It can avoid doing eina_file_dup() on a closed file for instance. This "fixes" a crash in eina_file_close with invalid files. Now I can go hunt the root cause... --- diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c index 5cbed8c..34bd7e8 100644 --- a/src/lib/eina/eina_file_common.c +++ b/src/lib/eina/eina_file_common.c @@ -60,6 +60,23 @@ Eina_Hash *_eina_file_cache = NULL; Eina_Lock _eina_file_lock_cache; +#if defined(EINA_SAFETY_CHECKS) && defined(EINA_MAGIC_DEBUG) +# define EINA_FILE_MAGIC_CHECK(f, ...) do { \ + if (EINA_UNLIKELY((f) == NULL)) \ + { \ + EINA_SAFETY_ERROR("safety check failed: " # f " == NULL"); \ + return __VA_ARGS__; \ + } \ + if (EINA_UNLIKELY((f)->__magic != EINA_FILE_MAGIC)) \ + { \ + EINA_MAGIC_FAIL(f, EINA_FILE_MAGIC); \ + return __VA_ARGS__; \ + } \ + } while (0) +#else +# define EINA_FILE_MAGIC_CHECK(f, ...) do {} while(0) +#endif + static char * _eina_file_escape(char *path, size_t len) { @@ -446,8 +463,9 @@ eina_file_virtualize(const char *virtual_name, const void *data, unsigned long l EAPI Eina_Bool eina_file_virtual(Eina_File *file) { - if (file) return file->virtual; - return EINA_FALSE; + if (!file) return EINA_FALSE; + EINA_FILE_MAGIC_CHECK(file, EINA_FALSE); + return file->virtual; } EAPI Eina_File * @@ -457,6 +475,7 @@ eina_file_dup(const Eina_File *f) if (file) { + EINA_FILE_MAGIC_CHECK(f, NULL); eina_lock_take(&file->lock); file->refcount++; eina_lock_release(&file->lock); @@ -486,7 +505,7 @@ eina_file_close(Eina_File *file) unsigned int length; unsigned int key; - EINA_SAFETY_ON_NULL_RETURN(file); + EINA_FILE_MAGIC_CHECK(file); eina_lock_take(&_eina_file_lock_cache); @@ -513,21 +532,21 @@ eina_file_close(Eina_File *file) EAPI size_t eina_file_size_get(const Eina_File *file) { - EINA_SAFETY_ON_NULL_RETURN_VAL(file, 0); + EINA_FILE_MAGIC_CHECK(file, 0); return file->length; } EAPI time_t eina_file_mtime_get(const Eina_File *file) { - EINA_SAFETY_ON_NULL_RETURN_VAL(file, 0); + EINA_FILE_MAGIC_CHECK(file, 0); return file->mtime; } EAPI const char * eina_file_filename_get(const Eina_File *file) { - EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); + EINA_FILE_MAGIC_CHECK(file, NULL); return file->filename; } @@ -622,7 +641,7 @@ eina_file_map_lines(Eina_File *file) { Eina_Lines_Iterator *it; - EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); + EINA_FILE_MAGIC_CHECK(file, NULL); if (file->length == 0) return NULL;