From ddcb27293af29880e0224fdc3ffec511da623f97 Mon Sep 17 00:00:00 2001 From: drepper Date: Tue, 14 Apr 1998 15:58:51 +0000 Subject: [PATCH] (__open_catalog): Fix problems with reading non-files. Always close file. --- catgets/open_catalog.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/catgets/open_catalog.c b/catgets/open_catalog.c index 62fb111e43..2197eb8363 100644 --- a/catgets/open_catalog.c +++ b/catgets/open_catalog.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper, . @@ -35,7 +35,7 @@ void __open_catalog (__nl_catd catalog) { - int fd; + int fd = -1; struct stat st; int swapping; @@ -169,7 +169,8 @@ __open_catalog (__nl_catd catalog) } } - if (fd < 0 || __fstat (fd, &st) < 0) + /* Avoid dealing with directories and block devices */ + if (fd < 0 || __fstat (fd, &st) < 0 || !S_ISREG (st.st_mode)) { catalog->status = nonexisting; goto unlock_return; @@ -225,6 +226,7 @@ __open_catalog (__nl_catd catalog) /* We don't need the file anymore. */ __close (fd); + fd = -1; /* Determine whether the file is a catalog file and if yes whether it is written using the correct byte order. Else we have to swap @@ -271,5 +273,7 @@ __open_catalog (__nl_catd catalog) /* Release the lock again. */ unlock_return: + if (fd != -1) + __close (fd); __libc_lock_unlock (catalog->lock); } -- 2.11.0