summaryrefslogtreecommitdiff
path: root/legacy/ethumb
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2010-07-08 22:37:04 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2010-07-08 22:37:04 +0000
commita2a0ab8d4caa530370beb96a11e449f1f4f98071 (patch)
treec752d380cf142fb5fc2e7ced71aab50369e4604b /legacy/ethumb
parentb07f70b85cfdfae36fce59028a6ec136a9d99ccc (diff)
Fix memory alignment and remove dead/useless code.
* those write to stderr were legacy from development, some of them were even wrongly accessing out-of-buffer memory; * some platforms cannot access non-aligned memory, like integers that are not aligned to sizeof(int) and do on. Change the generated message using memcpy to aligned memory before using them. Add comment to explain that; SVN revision: 50135
Diffstat (limited to 'legacy/ethumb')
-rw-r--r--legacy/ethumb/src/bin/ethumbd.c65
1 files changed, 22 insertions, 43 deletions
diff --git a/legacy/ethumb/src/bin/ethumbd.c b/legacy/ethumb/src/bin/ethumbd.c
index 6e29b4d869..333040c51b 100644
--- a/legacy/ethumb/src/bin/ethumbd.c
+++ b/legacy/ethumb/src/bin/ethumbd.c
@@ -357,57 +357,39 @@ _generated_cb(struct _Ethumbd *ed, Eina_Bool success, const char *thumb_path, co
357 ed->processing = NULL; 357 ed->processing = NULL;
358} 358}
359 359
360static Eina_Bool
361_write_safe(int fd, void *data, size_t size)
362{
363 unsigned char *buf = data;
364 size_t todo = size;
365 while (todo > 0)
366 {
367 size_t r = write(fd, buf, todo);
368 if (r > 0)
369 {
370 todo -= r;
371 buf += r;
372 }
373 else if ((r < 0) && (errno != EINTR))
374 {
375 ERR("could not write to fd=%d: %s", fd, strerror(errno));
376 return EINA_FALSE;
377 }
378 }
379 return EINA_TRUE;
380}
381
382static void 360static void
383_ethumbd_slave_cmd_ready(struct _Ethumbd *ed) 361_ethumbd_slave_cmd_ready(struct _Ethumbd *ed)
384{ 362{
385 char *bufcmd = ed->slave.bufcmd; 363 const char *bufcmd = ed->slave.bufcmd;
386 Eina_Bool *success; 364 Eina_Bool success;
387 const char *thumb_path = NULL; 365 const char *thumb_path = NULL;
388 const char *thumb_key = NULL; 366 const char *thumb_key = NULL;
389 int *size_path, *size_key; 367 int size_path, size_key;
390 368
391 success = (Eina_Bool *)bufcmd; 369 /* NOTE: accessing values directly on bufcmd breaks alignment
392 bufcmd += sizeof(*success); 370 * as the first item is an Eina_Bool (size 1) and second is
371 * an integer (size 4, alignment 4).
372 * Thus copy to stack values before using them, to have proper alignment.
373 */
374#define READVAL(dst) \
375 memcpy(&dst, bufcmd, sizeof(dst)); \
376 bufcmd += sizeof(dst);
393 377
394 size_path = (int *)bufcmd; 378 READVAL(success);
395 bufcmd += sizeof(*size_path);
396 379
397 _write_safe(STDERR_FILENO, bufcmd, ed->slave.scmd); 380 READVAL(size_path);
398 381 if (size_path)
399 if (*size_path)
400 { 382 {
401 thumb_path = bufcmd; 383 thumb_path = bufcmd;
402 bufcmd += *size_path; 384 bufcmd += size_path;
403 } 385 }
404 386
405 size_key = (int *)bufcmd; 387 READVAL(size_key);
406 bufcmd += sizeof(*size_key); 388 if (size_key) thumb_key = bufcmd;
407 389
408 if (*size_key) thumb_key = bufcmd; 390#undef READVAL
409 391
410 _generated_cb(ed, *success, thumb_path, thumb_key); 392 _generated_cb(ed, success, thumb_path, thumb_key);
411 393
412 free(ed->slave.bufcmd); 394 free(ed->slave.bufcmd);
413 ed->slave.bufcmd = NULL; 395 ed->slave.bufcmd = NULL;
@@ -423,7 +405,7 @@ _ethumbd_slave_alloc_cmd(struct _Ethumbd *ed, int ssize, char *sdata)
423 return 0; 405 return 0;
424 406
425 scmd = (int *)sdata; 407 scmd = (int *)sdata;
426 if (ssize < sizeof(*scmd)) { 408 if (ssize < (int)sizeof(*scmd)) {
427 ERR("could not read size of command."); 409 ERR("could not read size of command.");
428 return 0; 410 return 0;
429 } 411 }
@@ -435,7 +417,7 @@ _ethumbd_slave_alloc_cmd(struct _Ethumbd *ed, int ssize, char *sdata)
435} 417}
436 418
437static Eina_Bool 419static Eina_Bool
438_ethumbd_slave_data_read_cb(void *data, int type, void *event) 420_ethumbd_slave_data_read_cb(void *data, int type __UNUSED__, void *event)
439{ 421{
440 struct _Ethumbd *ed = data; 422 struct _Ethumbd *ed = data;
441 Ecore_Exe_Event_Data *ev = event; 423 Ecore_Exe_Event_Data *ev = event;
@@ -451,9 +433,6 @@ _ethumbd_slave_data_read_cb(void *data, int type, void *event)
451 ssize = ev->size; 433 ssize = ev->size;
452 sdata = ev->data; 434 sdata = ev->data;
453 435
454 if (!_write_safe(STDERR_FILENO, sdata, ssize))
455 return 0;
456
457 while (ssize > 0) 436 while (ssize > 0)
458 { 437 {
459 if (!ed->slave.bufcmd) 438 if (!ed->slave.bufcmd)
@@ -484,7 +463,7 @@ _ethumbd_slave_data_read_cb(void *data, int type, void *event)
484} 463}
485 464
486static Eina_Bool 465static Eina_Bool
487_ethumbd_slave_del_cb(void *data, int type, void *event) 466_ethumbd_slave_del_cb(void *data, int type __UNUSED__, void *event)
488{ 467{
489 struct _Ethumbd *ed = data; 468 struct _Ethumbd *ed = data;
490 Ecore_Exe_Event_Del *ev = event; 469 Ecore_Exe_Event_Del *ev = event;