cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=448cd69ab7568c10270ac3fa7f9f06ab6e0f00cc

commit 448cd69ab7568c10270ac3fa7f9f06ab6e0f00cc
Author: Shinwoo Kim <[email protected]>
Date:   Tue Sep 30 16:35:45 2014 +0200

    eina : check whether the file exists or not, before memory allocation of 
Eina_Module
    
    Summary:
    Please refer to https://phab.enlightenment.org/D1200
    
    Reviewers: raster, jpeg, zmike, cedric
    
    Subscribers: cedric, seoz
    
    Differential Revision: https://phab.enlightenment.org/D1334
---
 src/lib/eina/eina_module.c | 12 +++++++++++-
 src/lib/eina/eina_module.h |  6 +++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/lib/eina/eina_module.c b/src/lib/eina/eina_module.c
index 468fc5a..fbdeeeb 100644
--- a/src/lib/eina/eina_module.c
+++ b/src/lib/eina/eina_module.c
@@ -255,9 +255,19 @@ EAPI Eina_Module *eina_module_new(const char *file)
 {
    Eina_Module *m;
    size_t len;
+   struct stat st;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
-   /* TODO check that the file exists. Update doc too */
+
+   /* check that the file exists */
+   if (file[0] == '/' ||
+       file[0] == '.' ||
+       file[0] == '\\' ||
+       (file[0] != '\0' && file[1] == ':' && file[2] == '\\'))
+     {
+        if (stat(file, &st) == -1) return NULL;
+        if (!S_ISREG(st.st_mode)) return NULL;
+     }
 
    len = strlen(file);
    EINA_SAFETY_ON_FALSE_RETURN_VAL(len > 0, NULL);
diff --git a/src/lib/eina/eina_module.h b/src/lib/eina/eina_module.h
index 54d66a2..834dfa8 100644
--- a/src/lib/eina/eina_module.h
+++ b/src/lib/eina/eina_module.h
@@ -112,9 +112,9 @@ extern EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED;
  * @brief Return a new module.
  *
  * @param file The name of the file module to load.
- * @return A new module. If @p file is @c NULL, the function 
- * returns @c NULL, otherwise, it allocates an Eina_Module, stores
- * a duplicate string of @p file, sets its reference to @c 0 and
+ * @return A new module. If @p file is @c NULL, or if it does not exist,
+ * the function returns @c NULL, otherwise, it allocates an Eina_Module,
+ * stores a duplicate string of @p file, sets its reference to @c 0 and
  * its handle to @c NULL.
  *
  * When the new module is not needed anymore, use eina_module_free()

-- 


Reply via email to