aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-04-14 16:03:09 +0000
committerUlrich Drepper <drepper@redhat.com>1998-04-14 16:03:09 +0000
commit7762bc98a2dfefab2ac4cf9e60e3ad3822ef9d6d (patch)
treed8d6cbaa19699b5cfeeb3e8873fbbd71d0e106ea
parentUpdate. (diff)
downloadglibc-7762bc98a2dfefab2ac4cf9e60e3ad3822ef9d6d.tar.gz
glibc-7762bc98a2dfefab2ac4cf9e60e3ad3822ef9d6d.tar.bz2
glibc-7762bc98a2dfefab2ac4cf9e60e3ad3822ef9d6d.zip
(__open_catalog): Fix problems with reading non-files. Always close file.
-rw-r--r--catgets/open_catalog.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/catgets/open_catalog.c b/catgets/open_catalog.c
index 80d2899a36..fa4f077818 100644
--- a/catgets/open_catalog.c
+++ b/catgets/open_catalog.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>.
@@ -35,7 +35,7 @@
void
__open_catalog (__nl_catd catalog, int with_path)
{
- int fd;
+ int fd = -1;
struct stat st;
int swapping;
@@ -161,8 +161,9 @@ __open_catalog (__nl_catd catalog, int with_path)
}
}
- if (fd < 0 || __fstat (fd, &st) < 0)
+ if (fd < 0 || __fstat (fd, &st) < 0 || !S_ISREG (st.st_mode))
{
+ __close (fd);
catalog->status = nonexisting;
return;
}
@@ -194,6 +195,7 @@ __open_catalog (__nl_catd catalog, int with_path)
catalog->file_ptr = malloc (st.st_size);
if (catalog->file_ptr == NULL)
{
+ __close (fd);
catalog->status = nonexisting;
return;
}
@@ -205,6 +207,7 @@ __open_catalog (__nl_catd catalog, int with_path)
+ (st.st_size - todo)), todo);
if (now == 0)
{
+ __close (fd);
free ((void *) catalog->file_ptr);
catalog->status = nonexisting;
return;