eina: fix valgrind invalid read of size in eina_file_path_sanitize.
authorDaniel Hirt <daniel.hirt@samsung.com>
Wed, 4 Feb 2015 13:08:32 +0000 (14:08 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Wed, 4 Feb 2015 13:08:36 +0000 (14:08 +0100)
Summary:
Apparently eina_tmpstr_strlen counts the null character as well. This
doesn't follow how strlen works, as the latter excludes it from the count.
This resulted in mistreatment of the string in _eina_file_escape, with
tmp_str paths that had "../".

This fix will do for now, but it is advised that we avoid using
eina_tmpstr_strlen, to prevent such confusions in the future.

Test Plan:
The following lines will throw a valgrind 'invalid read of size 1' error
prior this fix:
  char *path = "home/mydir/../myfile";
  Eina_Tmpstr *tmp_str = eina_tmpstr_add(path);
  char *ret_path = eina_file_path_sanitize(path);

@fix

Reviewers: cedric, stefan_schmidt

Subscribers: tasn, cedric

Differential Revision: https://phab.enlightenment.org/D1929

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/lib/eina/eina_file_common.c

index 3e5b615..2c2406d 100644 (file)
@@ -353,7 +353,7 @@ eina_file_path_sanitize(const char *path)
    if (eina_file_path_relative(path))
      {
        result = eina_file_current_directory_get(path, len);
-       len = eina_tmpstr_strlen(result);
+       len = eina_tmpstr_strlen(result) - 1; /* tmpstr lengths include '/0' */
      }
    else
      result = path;