inotify: Fix safety after read in 3 places

Fixes Coverity issues:
 - CID 1039565
 - CID 1039566
This commit is contained in:
Jean-Philippe Andre 2014-10-27 22:57:53 +09:00
parent 6ace831372
commit 8d9c6c0a00
3 changed files with 6 additions and 3 deletions

View File

@ -328,7 +328,7 @@ _inotifyfd_handler(int fd, Fd_Flags flags, void *data EINA_UNUSED)
}
size = read(fd, buffer, sizeof(buffer));
while (i < size)
while ((i + (int) sizeof(struct inotify_event)) <= (int) size)
{
struct inotify_event *event;
int event_size;
@ -338,6 +338,7 @@ _inotifyfd_handler(int fd, Fd_Flags flags, void *data EINA_UNUSED)
event = (struct inotify_event *)&buffer[i];
event_size = sizeof(struct inotify_event) + event->len;
if ((event_size + i) > size) break ;
i += event_size;
ids = eina_hash_find(inotify_id_hash, &event->wd);

View File

@ -162,10 +162,11 @@ _ecore_file_monitor_inotify_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd
if (fd < 0) return ECORE_CALLBACK_RENEW;
size = read(fd, buffer, sizeof(buffer));
while (i < size)
while ((i + (int) sizeof(struct inotify_event)) <= (int) size)
{
event = (struct inotify_event *)&buffer[i];
event_size = sizeof(struct inotify_event) + event->len;
if ((event_size + i) > size) break ;
i += event_size;
em = _ecore_file_monitor_inotify_monitor_find(event->wd);

View File

@ -134,10 +134,11 @@ _eio_inotify_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fdh)
if (fd < 0) return ECORE_CALLBACK_RENEW;
size = read(fd, buffer, sizeof(buffer));
while (i < size)
while ((i + (int) sizeof(struct inotify_event)) <= (int) size)
{
event = (struct inotify_event *)&buffer[i];
event_size = sizeof(struct inotify_event) + event->len;
if ((event_size + i) > size) break ;
i += event_size;
backend = eina_hash_find(_inotify_monitors, &event->wd);