From f8d26b96b4230bf7d53e7504d6be0d9350cf4ed9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 8 Aug 2022 16:03:11 +0200 Subject: [PATCH] conf: don't error on empty files mmap of an empty file gives EINVAL. Avoid this and just don't update the config. --- src/pipewire/conf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pipewire/conf.c b/src/pipewire/conf.c index d5b3f2da4..9364542f5 100644 --- a/src/pipewire/conf.c +++ b/src/pipewire/conf.c @@ -405,12 +405,17 @@ static int conf_load(const char *path, struct pw_properties *conf) if (fstat(fd, &sbuf) < 0) goto error_close; - if ((data = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) - goto error_close; - close(fd); - count = pw_properties_update_string(conf, data, sbuf.st_size); - munmap(data, sbuf.st_size); + if (sbuf.st_size > 0) { + if ((data = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) + goto error_close; + + count = pw_properties_update_string(conf, data, sbuf.st_size); + munmap(data, sbuf.st_size); + } else { + count = 0; + } + close(fd); pw_log_info("%p: loaded config '%s' with %d items", conf, path, count);