core: handle import errors better

Check for NULL when importing a buffer and log a message instead of
trying to deref the NULL pointer and crash.

Add some more logging to mem when importing a bad fd.

See #3998
This commit is contained in:
Wim Taymans 2024-05-03 15:54:51 +02:00
parent 47a71325d6
commit 056d826c59
2 changed files with 5 additions and 2 deletions

View file

@ -81,7 +81,10 @@ static void core_event_add_mem(void *data, uint32_t id, uint32_t type, int fd, u
pw_log_debug("%p: add mem %u type:%u fd:%d flags:%08x", this, id, type, fd, flags); pw_log_debug("%p: add mem %u type:%u fd:%d flags:%08x", this, id, type, fd, flags);
m = pw_mempool_import(this->pool, flags, type, fd); m = pw_mempool_import(this->pool, flags, type, fd);
if (m->id != id) { if (m == NULL) {
pw_log_error("%p: can't import mem id:%u fd:%d: %m", this, id, fd);
pw_proxy_errorf(&this->proxy, -errno, "can't import mem id:%u: %m", id);
} else if (m->id != id) {
pw_log_error("%p: invalid mem id %u, fd:%d expected %u", pw_log_error("%p: invalid mem id %u, fd:%d expected %u",
this, id, fd, m->id); this, id, fd, m->id);
pw_proxy_errorf(&this->proxy, -EINVAL, "invalid mem id %u, expected %u", id, m->id); pw_proxy_errorf(&this->proxy, -EINVAL, "invalid mem id %u, expected %u", id, m->id);

View file

@ -648,7 +648,7 @@ struct pw_memblock * pw_mempool_import(struct pw_mempool *pool,
struct memblock *b; struct memblock *b;
if (fd < 0) { if (fd < 0) {
pw_log_error("%p: cannot import invalid fd", pool); pw_log_error("%p: cannot import invalid fd:%d", pool, fd);
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }