From e9ab85887d6bae3aaa486caffb9a15e9d8ec5498 Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 12 Mar 2018 23:31:49 +0100 Subject: fix race --- src/volumefs.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/volumefs.c b/src/volumefs.c index bc36ba3..392db8f 100644 --- a/src/volumefs.c +++ b/src/volumefs.c @@ -103,9 +103,10 @@ static int volumesfs_getattr(const char *path, struct stat *stbuf) stbuf->st_nlink = 2; } else { G_LOCK(mounts); - const gchar *mountpoint = g_hash_table_lookup(mounts, path + 1); + int mount_exists = g_hash_table_lookup(mounts, path + 1) != NULL; G_UNLOCK(mounts); - if (mountpoint) { + + if (mount_exists) { stbuf->st_mode = S_IFLNK | 0444; stbuf->st_nlink = 1; } else { @@ -147,13 +148,20 @@ static int volumesfs_readlink(const char *path, char *buf, size_t size) if (strcmp(path, "/") == 0) { return -EINVAL; } + if (size == 0) { + return -EINVAL; + } G_LOCK(mounts); + int mount_exists = 0; gchar *mountpoint = g_hash_table_lookup(mounts, path + 1); + if (mountpoint) { + g_strlcpy(buf, mountpoint, size); + mount_exists = 1; + } G_UNLOCK(mounts); - if (mountpoint) { - strcpy(buf, mountpoint); + if (mount_exists) { return 0; } else { return -ENOENT; -- cgit v1.2.3