projects
/
platform
/
core
/
appfw
/
xdgmime.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix TOCTOU issues
[platform/core/appfw/xdgmime.git]
/
xdgmime
/
src
/
xdgmime.c
diff --git
a/xdgmime/src/xdgmime.c
b/xdgmime/src/xdgmime.c
index
9e0e5e7
..
f898cc1
100644
(file)
--- a/
xdgmime/src/xdgmime.c
+++ b/
xdgmime/src/xdgmime.c
@@
-533,6
+533,7
@@
xdg_mime_get_mime_type_for_file (const char *file_name,
struct stat buf;
const char *base_name;
int n;
struct stat buf;
const char *base_name;
int n;
+ int fd;
if (file_name == NULL)
return NULL;
if (file_name == NULL)
return NULL;
@@
-550,9
+551,17
@@
xdg_mime_get_mime_type_for_file (const char *file_name,
if (n == 1)
return mime_types[0];
if (n == 1)
return mime_types[0];
+ file = fopen (file_name, "r");
+ if (file == NULL)
+ {
+ free (data);
+ return XDG_MIME_TYPE_UNKNOWN;
+ }
+
if (!statbuf)
{
if (!statbuf)
{
- if (stat (file_name, &buf) != 0)
+ fd = fileno(file);
+ if (fstat (fd, &buf) != 0)
return XDG_MIME_TYPE_UNKNOWN;
statbuf = &buf;
return XDG_MIME_TYPE_UNKNOWN;
statbuf = &buf;
@@
-569,13
+578,6
@@
xdg_mime_get_mime_type_for_file (const char *file_name,
if (data == NULL)
return XDG_MIME_TYPE_UNKNOWN;
if (data == NULL)
return XDG_MIME_TYPE_UNKNOWN;
- file = fopen (file_name, "r");
- if (file == NULL)
- {
- free (data);
- return XDG_MIME_TYPE_UNKNOWN;
- }
-
bytes_read = fread (data, 1, max_extent, file);
if (ferror (file))
{
bytes_read = fread (data, 1, max_extent, file);
if (ferror (file))
{