aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-04-18 15:55:12 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-04-18 17:30:50 +0900
commit39baea1053ef0dd6bf32147a53e45647f4bcec3d (patch)
tree377a2011f9ff5501eaeb41bd77457daba42364ac /src/bin/efreet
parentevas key lock state set - remove dead code (diff)
downloadefl-39baea1053ef0dd6bf32147a53e45647f4bcec3d.tar.gz
efreet cache create - check return values of i/o funcs
this is pretty harmless but it checks these and at least reports an error... this fixes CID 1361941 + 1361940 @fix
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreet_mime_cache_create.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/bin/efreet/efreet_mime_cache_create.c b/src/bin/efreet/efreet_mime_cache_create.c
index e452b9847e..7e45a5fa28 100644
--- a/src/bin/efreet/efreet_mime_cache_create.c
+++ b/src/bin/efreet/efreet_mime_cache_create.c
@@ -220,6 +220,7 @@ find_off(const char *str, Eina_List *strlist, Eina_List *offlist)
}
return (void *)-1;
}
+
static void
store_cache(const char *out)
{
@@ -241,7 +242,8 @@ store_cache(const char *out)
f = fopen(buf, "wb");
if (!f) return;
// write file magic - first 16 bytes
- fwrite("EfrEeT-MiMeS-001", 16, 1, f);
+ if (fwrite("EfrEeT-MiMeS-001", 16, 1, f) != 1)
+ goto write_error;
// note: all offsets are in bytes from start of file
//
// "EfrEeT-MiMeS-001" <- magic 16 byte header
@@ -290,54 +292,81 @@ store_cache(const char *out)
(eina_list_count(glob_mimes_sorted) * sizeof(int) * 2);
val = eina_list_count(mimes_sorted);
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
EINA_LIST_FOREACH(mimes_str_offsets, l, ptr)
{
val = (int)((long)ptr) + str_start;
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
}
val = eina_list_count(extn_mimes_sorted);
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
ll = extn_mimes_sorted;
EINA_LIST_FOREACH(extn_mimes_str_offsets, l, ptr)
{
val = (int)((long)ptr) + str_start + mimes_str_len;
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
s = eina_hash_find(extn_mimes, ll->data);
ptr = find_off(s, mimes_sorted, mimes_str_offsets);
val = (int)((long)ptr) + str_start;
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
ll = ll->next;
}
val = eina_list_count(glob_mimes_sorted);
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
ll = glob_mimes_sorted;
EINA_LIST_FOREACH(glob_mimes_str_offsets, l, ptr)
{
val = (int)((long)ptr) + str_start + mimes_str_len + extn_mimes_str_len;
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
s = eina_hash_find(glob_mimes, ll->data);
ptr = find_off(s, mimes_sorted, mimes_str_offsets);
val = (int)((long)ptr) + str_start;
- fwrite(&val, sizeof(val), 1, f);
+ if (fwrite(&val, sizeof(val), 1, f) != 1)
+ goto write_error;
ll = ll->next;
}
EINA_LIST_FOREACH(mimes_sorted, l, s)
{
- fwrite(s, strlen(s) + 1, 1, f);
+ if (fwrite(s, strlen(s) + 1, 1, f) != 1)
+ goto write_error;
}
EINA_LIST_FOREACH(extn_mimes_sorted, l, s)
{
- fwrite(s, strlen(s) + 1, 1, f);
+ if (fwrite(s, strlen(s) + 1, 1, f) != 1)
+ goto write_error;
}
EINA_LIST_FOREACH(glob_mimes_sorted, l, s)
{
- fwrite(s, strlen(s) + 1, 1, f);
+ if (fwrite(s, strlen(s) + 1, 1, f) != 1)
+ goto write_error;
}
- fclose(f);
- rename(buf, out);
+ if (fclose(f) != 0)
+ {
+ ERR("Cannot close file %s", buf);
+ f = NULL;
+ goto error;
+ }
+ if (rename(buf, out) != 0)
+ {
+ ERR("Cannot rename %s to %s", buf, out);
+ f = NULL;
+ goto error;
+ }
+ return;
+write_error:
+ ERR("Cannot write to %s", buf);
+error:
+ if (f) fclose(f);
+ if (unlink(buf) != 0) WRN("Cannot delete tmp file %s", buf);
}
int