From bb451c37bc05c8a33130e6b93020378d742f0ca2 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 18 Jun 2009 05:33:27 +0000 Subject: libglusterfs: Prevent gf_fd_put'ing of unallocated fd Signed-off-by: Anand V. Avati --- libglusterfs/src/fd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index f67bdc828..b28fb047e 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -343,11 +343,21 @@ gf_fd_put (fdtable_t *fdtable, int32_t fd) pthread_mutex_lock (&fdtable->lock); { fde = &fdtable->fdentries[fd]; - fdptr = fde->fd; + /* If the entry is not allocated, put operation must return + * without doing anything. + * This has the potential of masking out any bugs in a user of + * fd that ends up calling gf_fd_put twice for the same fd or + * for an unallocated fd, but thats a price we have to pay for + * ensuring sanity of our fd-table. + */ + if (fde->next_free != GF_FDENTRY_ALLOCATED) + goto unlock_out; + fdptr = fde->fd; fde->fd = NULL; fde->next_free = fdtable->first_free; fdtable->first_free = fd; } +unlock_out: pthread_mutex_unlock (&fdtable->lock); if (fdptr) { -- cgit