diff options
author | Javier <dev.git@javispedro.com> | 2018-03-12 23:31:49 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2018-03-12 23:31:57 +0100 |
commit | e9ab85887d6bae3aaa486caffb9a15e9d8ec5498 (patch) | |
tree | f9e2512777f157ff1c7f1d8e5597b1985e811008 | |
parent | 54e7d8476ca3b41cbb38226e58241e1920ad357a (diff) | |
download | volumefs-e9ab85887d6bae3aaa486caffb9a15e9d8ec5498.tar.gz volumefs-e9ab85887d6bae3aaa486caffb9a15e9d8ec5498.zip |
fix race
-rw-r--r-- | src/volumefs.c | 16 |
1 files 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; |