1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Copy struct inotify_event entries to avoid alignment problems

When reading the inotify FD, we get back a sequence of
struct inotify_event, each with variable length data following.
It is not safe to simply cast from the char *buf to the
struct inotify_event struct since this may violate data
alignment rules. Thus we must copy from the char *buf
into the struct inotify_event instance before accessing
the data.

uml/uml_driver.c: In function 'umlInotifyEvent':
uml/uml_driver.c:327:13: warning: cast increases required alignment of target type [-Wcast-align]
         e = (struct inotify_event *)tmp;

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-04-03 14:33:56 +01:00
parent c4f9edf1a1
commit 7e6aabc61f

@ -300,7 +300,7 @@ umlInotifyEvent(int watch,
void *data) void *data)
{ {
char buf[1024]; char buf[1024];
struct inotify_event *e; struct inotify_event e;
int got; int got;
char *tmp, *name; char *tmp, *name;
struct uml_driver *driver = data; struct uml_driver *driver = data;
@ -321,20 +321,20 @@ reread:
tmp = buf; tmp = buf;
while (got) { while (got) {
if (got < sizeof(struct inotify_event)) if (got < sizeof(e))
goto cleanup; /* bad */ goto cleanup; /* bad */
e = (struct inotify_event *)tmp; memcpy(&e, tmp, sizeof(e));
tmp += sizeof(struct inotify_event); tmp += sizeof(e);
got -= sizeof(struct inotify_event); got -= sizeof(e);
if (got < e->len) if (got < e.len)
goto cleanup; goto cleanup;
tmp += e->len; tmp += e.len;
got -= e->len; got -= e.len;
name = (char *)&(e->name); name = (char *)&(e.name);
dom = virDomainObjListFindByName(driver->domains, name); dom = virDomainObjListFindByName(driver->domains, name);
@ -342,7 +342,7 @@ reread:
continue; continue;
} }
if (e->mask & IN_DELETE) { if (e.mask & IN_DELETE) {
VIR_DEBUG("Got inotify domain shutdown '%s'", name); VIR_DEBUG("Got inotify domain shutdown '%s'", name);
if (!virDomainObjIsActive(dom)) { if (!virDomainObjIsActive(dom)) {
virObjectUnlock(dom); virObjectUnlock(dom);
@ -359,7 +359,7 @@ reread:
dom); dom);
dom = NULL; dom = NULL;
} }
} else if (e->mask & (IN_CREATE | IN_MODIFY)) { } else if (e.mask & (IN_CREATE | IN_MODIFY)) {
VIR_DEBUG("Got inotify domain startup '%s'", name); VIR_DEBUG("Got inotify domain startup '%s'", name);
if (virDomainObjIsActive(dom)) { if (virDomainObjIsActive(dom)) {
virObjectUnlock(dom); virObjectUnlock(dom);