Commit Graph

74 Commits

Author SHA1 Message Date
Cedric BAIL 9d8549f7a3 eina: add an API to correctly do close on exec. 2017-04-18 16:53:26 -07:00
Cedric Bail 4766316935 eina: force copy of not copied virtualized file while doing an eina_file_dup.
The other way around is pretty much impossible as you don't know who does
an eina_file_dup and for how long they keep there reference.

T5234
2017-03-08 12:24:41 -08:00
Ivan Furs 8a10ef10cb eina_file: delete handle->fm(handel of function CreateFileMapping)
Summary: CreateFileMapping return handle. The handle before use is always closed. This handle can be immediately closed after use.

Reviewers: cedric, raster, vtorri, rimmed, an.kroitor, FurryMyad, NikaWhite

Reviewed By: raster

Subscribers: artem.popov, cedric, jpeg

Tags: #windows

Differential Revision: https://phab.enlightenment.org/D4699
2017-03-06 19:18:46 +09:00
Jean-Philippe Andre 509cce5e43 eina: Set magic number in eina_file_virtualize
This fixes make check
2016-12-09 11:08:38 +09:00
Jean-Philippe Andre f1d546df5d eina: Set magic type name for Eina_File 2016-12-08 16:30:34 +09:00
Jean-Philippe Andre 208e152baf 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...
2016-12-08 16:30:34 +09:00
Carsten Haitzler ed1101d994 fix possible eina file shutdown issue
i am not sure as i cannto reproduce this, but i hope this fixes T4677
by ensuring if eina_file_shutdown is called it cannto double-free a
hash.
2016-10-14 16:40:09 +09:00
Carsten Haitzler 7ee4eba33f efl - new cmp "fix" code - remove one duplicated cmp 2016-05-26 12:49:58 +09:00
Carsten Haitzler 41842ca9f9 efl - fix many bounds over/underflow where we use int for ptr cmp
this addresses more things brought up in comments in

fixes T3638 commentd

@fix
2016-05-26 12:17:07 +09:00
Jean-Philippe Andre e472f97d96 Eina: Fix eina_file_mk[ds]temp when a path is passed
If the template is a path, mkstemp and mkdtemp would fail
miserably as they would try to create a file inside
/run/user/1000//path/to/file.XXXXXX even if the path did not
exist.

This patch fixes that by creating temp files inside the sys temp
dir iif the templatename is just a basic name without path
separator.

@fix
2016-01-19 18:18:29 +09:00
Vincent Torri 9e5852fcfb eina: use eina_file_path_join() and eina_environment_tmp_get() when needed
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2015-12-01 12:13:12 -08:00
Vincent Torri a1243410a7 eina/efreet: open file with binary file on Windows
@fix

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2015-11-06 10:53:29 -08:00
Cedric BAIL a089818335 eina: correctly prepare path before sanitizing it. 2015-10-28 06:45:10 +01:00
Cedric BAIL 046d806388 Revert "Eina: Fix 58b194e0ad56fe83cce3946a5deb0045ee0cbce2"
This reverts commit 22b45f220c.

eina_file_cleanup always does an eina_tmpstr_del. This is now capable of doing
double or even triple free in some case.
2015-10-28 06:38:14 +01:00
Vincent Torri 22b45f220c Eina: Fix 58b194e0ad
Fixes the windows build as it has a matching implementation for eina_file_cleanup.

Fixes T2804
2015-10-28 03:34:10 +01:00
Cedric BAIL 58b194e0ad eina: make sure to cleanup the right string. 2015-10-23 12:32:02 -07:00
Andy Williams 128a78940b eina: include blank lines in file iterator T2237
any line that would not have been included before has length == 0
2015-03-27 21:42:45 +00:00
Andy Williams a6290f8505 eina: Change newline parsing to handle crlf better
Adjust test to demonstrate failure, existing code only worked for
windows newlines on blank line.
@fix T2236
2015-03-27 09:56:22 +00:00
Jaeun Choi 3cd2801be7 eina: safety check for NULL pointer
data should not be NULL. it is used as the source of memcpy.

@fix
2015-03-19 16:15:20 +09:00
Tom Hacohen 8fbee3fac0 Eina tmpstr: remove usage of tmpstr_strlen(). 2015-02-09 14:02:40 +00:00
Daniel Hirt 7143bd7fb5 eina: fix valgrind invalid read of size in eina_file_path_sanitize.
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>
2015-02-04 14:08:36 +01:00
Daniel Hirt 7cbf22212f Revert "eina: eina_file - fix "invalid read of size 1" in valgrind"
This reverts commit f52f562891.

This is reverted because it breaks eina_file_path_sanitize when using
  "/../" in paths, for example:
eina_file_path_sanitize("/home/../mydir/myfile")
  returns: "/mydir/myfili"

What invalid read size does this fix? Why was no test case specified?
Anyway, this change affects too much code to leave it in like this.
2015-02-02 14:41:37 +02:00
Romain Perier f52f562891 eina: eina_file - fix "invalid read of size 1" in valgrind
@fix

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2015-01-30 10:49:58 +01:00
Jean-Philippe Andre 03cc403228 Eina file: Fix calls to getenv
There seems to be an intent to check that UID==EUID
before calling getenv to get the temp directory.
But that was lost in commits 61478af3a6 and
then in e105abc99e.
2014-10-30 18:23:49 +09:00
Stefan Schmidt e105abc99e eina_file: Give TMPDIR presedence over XDG_RUNTIME_DIR when defined
XDG_RUNTIME_DIR gives us a nice securty benefit by only allowing the
same user to read wand write files.

In some configuration this is problematic though. If one looks at the
bug report this fixes  for example you can see that there are build
scripts that use a special build user.

The way this has always worked on unix is that you can define your
own tempdir with TMPDIR. When I was making the original change towards
XDG_RUNTIME_DIR I expected some trouble with it but it worked quite
well so far.

To avoid breaking scripts out there and maybe configurations we
haven't tested yet give TMPDIR precedence over XDG_RUNTIME_DIR.

Fixes T1766
2014-10-29 15:51:11 +01:00
Vincent Torri 291c546143 eina: do no use umask on Windows in eina_file_mkstemp()
umask() sets the permissions of the file to read-only on Windows
(see umask documentation on MSDN).
This breaks the creation of .edj file (epp needs to modify the
created file).
Anyway, on Windows, permissions should be given to anybody.

@fix

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
2014-09-23 16:41:32 +02:00
Stefan Schmidt 61478af3a6 eina_file: Try to use XDG_RUNTIME_DIR for tmp dir first
Instead using $TMPDIR and falling back to /tmp we now try $XDG_RUNTIME_DIR
first.

"$XDG_RUNTIME_DIR defines the base directory relative to which user-specific
non-essential runtime files and other file objects (such as sockets, named
pipes, ...) should be stored. The directory MUST be owned by the user, and
he MUST be the only one having read and write access to it. Its Unix access
mode MUST be 0700."

While improving our security by isolating these files from other users this
has the potential to break things. I have not seen any breakage in testing
but keep this commit in mind if something strange happens on your system.
2014-09-12 09:12:52 +02:00
Andrii Kroitor 38147da036 eina_file: fixing wrong return value on access problems in file copy process
Summary:
when dest directory is protected from writing success value was returned
@fix

Reviewers: seoz, cedric, Hermet

Reviewed By: Hermet

Subscribers: cedric, reutskiy.v.v

Differential Revision: https://phab.enlightenment.org/D1366
2014-08-27 19:47:16 +09:00
Daniel Kolesa 987cde5f35 Revert "eina: new API: eina_file_path_basename"
This reverts commit 68282f8c42.

This is actually not needed because of presence of basename in Evil.
2014-07-23 19:38:08 +01:00
Daniel Kolesa 68282f8c42 eina: new API: eina_file_path_basename 2014-07-23 17:04:04 +01:00
Cedric BAIL 72aca66f8d eina: win32 and linux version code are the same. Sharing code is better. 2014-07-14 15:46:54 +02:00
ChunEon Park cc68ef1f22 eina - fixed typo 2014-07-07 20:22:06 +09:00
ChunEon Park 328d28a7f4 eina/file - revert 18be4c50d9
I realized that's not a bug in eina but user usage was inccorect.
revert the patch

@fix
2014-05-31 18:34:48 +09:00
Jean-Philippe Andre e50bcc937c Eina: Fix mistake in a previous patch
Suffix length was not computed properly.
Also, the change on eina_mkstemps was a @feature:
add file extension support when creating temporary files
2014-04-02 14:53:00 +09:00
Jean-Philippe Andre 0fdb02fb51 Eina: Add support for file extensions in eina_mkstemp
Using mkstemps
2014-04-02 11:54:44 +09:00
Cedric Bail 3e89295c73 eina: fix memory leak of inserting the wrong value in the hash.
We where inserting the pointer data instead of the pointer, leading to
unaligned access on Sparc (Thanks Lutin to report it and Debian tools/infra
to help us catch it) and also a memory leak.
2014-01-11 21:38:55 +09:00
Carsten Haitzler e8c13118eb fix mingw build for setuid fix/checks 2014-01-08 22:06:41 +09:00
Carsten Haitzler b95ef3801f setuid safeness - ensure if an app that is setuid doesn't do bad things
this makes efl ignore certain env vars for thnigs and entirely removes
user modules (that no one ever used) etc. etc. to ensure that *IF* an
app is setuid, there isn't a priv escalation path that is easy.
2014-01-08 19:46:23 +09:00
Carsten Haitzler e4b029da0b eina - eina_file - fix leak of fd is fd is 0
this should fix CID 1039181
2013-12-13 21:26:05 +09:00
Cedric Bail 62b469749a eina: fix the crash seen by some during rebuild.
Before this patch, we were unconditionnaly destroying the Eina_File if that one
did change on disk. We also make sure that we remove the right entry from the cache
if the file did change there.
2013-11-21 14:49:08 +09:00
Cedric Bail 0cfb40b7fb eina: cleanup file destruction and reintroduce EINA_MAGIC use. 2013-11-20 20:08:44 +09:00
Jérémy Zurcher 58b578c9b0 eina: fix a possible race condition during eina_file_close.
replay 7e8fb93 without the breakage
2013-11-20 10:22:00 +01:00
Jérémy Zurcher 8a3e021298 Revert "eina: fix a possible race condition during eina_file_close."
it breaks everything

This reverts commit 7e8fb93206.
2013-11-20 10:22:00 +01:00
Cedric Bail 7e8fb93206 eina: fix a possible race condition during eina_file_close.
The lock on the main hash was taken to late (after we took the decision
to remove the targeted Eina_File from the cache), this means it was possible
to get an Eina_File from the cache that was going to be removed. This patch
attempt to fix that potential race condition.

Hopefully should fix T461.
2013-11-20 13:02:37 +09:00
Cedric Bail 44f539e1a3 eina: fix eina_hash_int64 on Windows system. 2013-11-09 20:07:27 +09:00
Cedric Bail 687e4ae744 eina: roll const into Eina_File API.
Note that eina_file_dup is const from the caller perspective as it
will return a fresh "non const" Eina_File that it will be able to
manipulate as it like.
2013-11-04 11:26:59 +09:00
Cedric Bail 60a34c1cd0 eina: avoid possible race condition when unreffing an Eina_File. 2013-10-28 18:32:40 +09:00
Cedric Bail 46447c95aa eina: just for a little bit of better portability. 2013-10-16 16:54:36 +09:00
Sebastian Dransfeld 0b26b1bd89 eina: And guard the right function with umask
Thanks Cedric.
2013-10-16 04:56:51 +02:00
Sebastian Dransfeld 7576ff00f3 Set secure file permissions for temporary file
From glibc mkstemp man page:
       In glibc versions 2.06 and earlier, the file is created with
       permissions 0666, that is, read and write for all users.  This old
       behavior may be a security risk, especially since other UNIX flavors
       use 0600, and somebody might overlook this detail when porting
       programs.  POSIX.1-2008 adds a requirement that the file be created
       with mode 0600.

       More generally, the POSIX specification of mkstemp() does not say
       anything about file modes, so the application should make sure its
       file mode creation mask (see umask(2)) is set appropriately before
       calling mkstemp() (and mkostemp()).

And:
	http://cwe.mitre.org/data/definitions/377.html
2013-10-16 04:28:53 +02:00