summaryrefslogtreecommitdiff
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
parent4a4b0d87948632556f21ac206e42819af1e9db5e (diff)
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)
220 } 220 }
221 return (void *)-1; 221 return (void *)-1;
222} 222}
223
223static void 224static void
224store_cache(const char *out) 225store_cache(const char *out)
225{ 226{
@@ -241,7 +242,8 @@ store_cache(const char *out)
241 f = fopen(buf, "wb"); 242 f = fopen(buf, "wb");
242 if (!f) return; 243 if (!f) return;
243 // write file magic - first 16 bytes 244 // write file magic - first 16 bytes
244 fwrite("EfrEeT-MiMeS-001", 16, 1, f); 245 if (fwrite("EfrEeT-MiMeS-001", 16, 1, f) != 1)
246 goto write_error;
245 // note: all offsets are in bytes from start of file 247 // note: all offsets are in bytes from start of file
246 // 248 //
247 // "EfrEeT-MiMeS-001" <- magic 16 byte header 249 // "EfrEeT-MiMeS-001" <- magic 16 byte header
@@ -290,54 +292,81 @@ store_cache(const char *out)
290 (eina_list_count(glob_mimes_sorted) * sizeof(int) * 2); 292 (eina_list_count(glob_mimes_sorted) * sizeof(int) * 2);
291 293
292 val = eina_list_count(mimes_sorted); 294 val = eina_list_count(mimes_sorted);
293 fwrite(&val, sizeof(val), 1, f); 295 if (fwrite(&val, sizeof(val), 1, f) != 1)
296 goto write_error;
294 EINA_LIST_FOREACH(mimes_str_offsets, l, ptr) 297 EINA_LIST_FOREACH(mimes_str_offsets, l, ptr)
295 { 298 {
296 val = (int)((long)ptr) + str_start; 299 val = (int)((long)ptr) + str_start;
297 fwrite(&val, sizeof(val), 1, f); 300 if (fwrite(&val, sizeof(val), 1, f) != 1)
301 goto write_error;
298 } 302 }
299 303
300 val = eina_list_count(extn_mimes_sorted); 304 val = eina_list_count(extn_mimes_sorted);
301 fwrite(&val, sizeof(val), 1, f); 305 if (fwrite(&val, sizeof(val), 1, f) != 1)
306 goto write_error;
302 ll = extn_mimes_sorted; 307 ll = extn_mimes_sorted;
303 EINA_LIST_FOREACH(extn_mimes_str_offsets, l, ptr) 308 EINA_LIST_FOREACH(extn_mimes_str_offsets, l, ptr)
304 { 309 {
305 val = (int)((long)ptr) + str_start + mimes_str_len; 310 val = (int)((long)ptr) + str_start + mimes_str_len;
306 fwrite(&val, sizeof(val), 1, f); 311 if (fwrite(&val, sizeof(val), 1, f) != 1)
312 goto write_error;
307 s = eina_hash_find(extn_mimes, ll->data); 313 s = eina_hash_find(extn_mimes, ll->data);
308 ptr = find_off(s, mimes_sorted, mimes_str_offsets); 314 ptr = find_off(s, mimes_sorted, mimes_str_offsets);
309 val = (int)((long)ptr) + str_start; 315 val = (int)((long)ptr) + str_start;
310 fwrite(&val, sizeof(val), 1, f); 316 if (fwrite(&val, sizeof(val), 1, f) != 1)
317 goto write_error;
311 ll = ll->next; 318 ll = ll->next;
312 } 319 }
313 320
314 val = eina_list_count(glob_mimes_sorted); 321 val = eina_list_count(glob_mimes_sorted);
315 fwrite(&val, sizeof(val), 1, f); 322 if (fwrite(&val, sizeof(val), 1, f) != 1)
323 goto write_error;
316 ll = glob_mimes_sorted; 324 ll = glob_mimes_sorted;
317 EINA_LIST_FOREACH(glob_mimes_str_offsets, l, ptr) 325 EINA_LIST_FOREACH(glob_mimes_str_offsets, l, ptr)
318 { 326 {
319 val = (int)((long)ptr) + str_start + mimes_str_len + extn_mimes_str_len; 327 val = (int)((long)ptr) + str_start + mimes_str_len + extn_mimes_str_len;
320 fwrite(&val, sizeof(val), 1, f); 328 if (fwrite(&val, sizeof(val), 1, f) != 1)
329 goto write_error;
321 s = eina_hash_find(glob_mimes, ll->data); 330 s = eina_hash_find(glob_mimes, ll->data);
322 ptr = find_off(s, mimes_sorted, mimes_str_offsets); 331 ptr = find_off(s, mimes_sorted, mimes_str_offsets);
323 val = (int)((long)ptr) + str_start; 332 val = (int)((long)ptr) + str_start;
324 fwrite(&val, sizeof(val), 1, f); 333 if (fwrite(&val, sizeof(val), 1, f) != 1)
334 goto write_error;
325 ll = ll->next; 335 ll = ll->next;
326 } 336 }
327 EINA_LIST_FOREACH(mimes_sorted, l, s) 337 EINA_LIST_FOREACH(mimes_sorted, l, s)
328 { 338 {
329 fwrite(s, strlen(s) + 1, 1, f); 339 if (fwrite(s, strlen(s) + 1, 1, f) != 1)
340 goto write_error;
330 } 341 }
331 EINA_LIST_FOREACH(extn_mimes_sorted, l, s) 342 EINA_LIST_FOREACH(extn_mimes_sorted, l, s)
332 { 343 {
333 fwrite(s, strlen(s) + 1, 1, f); 344 if (fwrite(s, strlen(s) + 1, 1, f) != 1)
345 goto write_error;
334 } 346 }
335 EINA_LIST_FOREACH(glob_mimes_sorted, l, s) 347 EINA_LIST_FOREACH(glob_mimes_sorted, l, s)
336 { 348 {
337 fwrite(s, strlen(s) + 1, 1, f); 349 if (fwrite(s, strlen(s) + 1, 1, f) != 1)
350 goto write_error;
338 } 351 }
339 fclose(f); 352 if (fclose(f) != 0)
340 rename(buf, out); 353 {
354 ERR("Cannot close file %s", buf);
355 f = NULL;
356 goto error;
357 }
358 if (rename(buf, out) != 0)
359 {
360 ERR("Cannot rename %s to %s", buf, out);
361 f = NULL;
362 goto error;
363 }
364 return;
365write_error:
366 ERR("Cannot write to %s", buf);
367error:
368 if (f) fclose(f);
369 if (unlink(buf) != 0) WRN("Cannot delete tmp file %s", buf);
341} 370}
342 371
343int 372int