mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-30 08:40:07 +00:00
03d2730b44
Robin Hack discovered Samba would enter an infinite loop processing certain quota-related requests. We eventually tracked this down to a glibc issue. Running a (simplified) test case under strace shows that /etc/passwd is continuously opened and closed: … open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3 lseek(3, 0, SEEK_CUR) = 0 read(3, "root❌0:0:root:/root:/bin/bash\n"..., 4096) = 2717 lseek(3, 2717, SEEK_SET) = 2717 close(3) = 0 open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3 lseek(3, 0, SEEK_CUR) = 0 lseek(3, 0, SEEK_SET) = 0 read(3, "root❌0:0:root:/root:/bin/bash\n"..., 4096) = 2717 lseek(3, 2717, SEEK_SET) = 2717 close(3) = 0 open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3 lseek(3, 0, SEEK_CUR) = 0 … The lookup function implementation in nss/nss_files/files-XXX.c:DB_LOOKUP has code to prevent that. It is supposed skip closing the input file if it was already open. /* Reset file pointer to beginning or open file. */ \ status = internal_setent (keep_stream); \ \ if (status == NSS_STATUS_SUCCESS) \ { \ /* Tell getent function that we have repositioned the file pointer. */ \ last_use = getby; \ \ while ((status = internal_getent (result, buffer, buflen, errnop \ H_ERRNO_ARG EXTRA_ARGS_VALUE)) \ == NSS_STATUS_SUCCESS) \ { break_if_match } \ \ if (! keep_stream) \ internal_endent (); \ } \ keep_stream is initialized from the stayopen flag in internal_setent. internal_setent is called from the set*ent implementation as: status = internal_setent (stayopen); However, for non-host database, this flag is always 0, per the STAYOPEN magic in nss/getXXent_r.c. Thus, the fix is this: - status = internal_setent (stayopen); + status = internal_setent (1); This is not a behavioral change even for the hosts database (where the application can specify the stayopen flag) because with a call to sethostent(0), the file handle is still not closed in the implementation of gethostent.
124 lines
3.9 KiB
Makefile
124 lines
3.9 KiB
Makefile
# Copyright (C) 1996-2015 Free Software Foundation, Inc.
|
|
# This file is part of the GNU C Library.
|
|
|
|
# The GNU C Library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
# The GNU C Library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with the GNU C Library; if not, see
|
|
# <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
# Makefile for name service switch.
|
|
#
|
|
subdir := nss
|
|
|
|
include ../Makeconfig
|
|
|
|
headers := nss.h
|
|
|
|
# This is the trivial part which goes into libc itself.
|
|
routines = nsswitch getnssent getnssent_r digits_dots \
|
|
$(addsuffix -lookup,$(databases))
|
|
|
|
# These are the databases that go through nss dispatch.
|
|
# Caution: if you add a database here, you must add its real name
|
|
# in databases.def, too.
|
|
databases = proto service hosts network grp pwd ethers \
|
|
spwd netgrp alias sgrp
|
|
|
|
ifneq (,$(filter sunrpc,$(subdirs)))
|
|
databases += key rpc
|
|
have-sunrpc := 1
|
|
else
|
|
have-sunrpc := 0
|
|
endif
|
|
CPPFLAGS-getent.c = -DHAVE_SUNRPC=$(have-sunrpc)
|
|
|
|
others := getent makedb
|
|
install-bin := getent makedb
|
|
makedb-modules = xmalloc hash-string
|
|
extra-objs += $(makedb-modules:=.o)
|
|
|
|
tests = test-netdb tst-nss-test1 test-digits-dots tst-nss-getpwent
|
|
xtests = bug-erange
|
|
|
|
# Specify rules for the nss_* modules. We have some services.
|
|
services := files db
|
|
|
|
extra-libs = $(services:%=libnss_%)
|
|
# These libraries will be built in the `others' pass rather than
|
|
# the `lib' pass, because they depend on libc.so being built already.
|
|
extra-libs-others = $(extra-libs)
|
|
|
|
# The sources are found in the appropriate subdir.
|
|
subdir-dirs = $(services:%=nss_%)
|
|
vpath %.c $(subdir-dirs) ../locale/programs ../intl
|
|
|
|
|
|
libnss_files-routines := $(addprefix files-,$(databases)) \
|
|
files-initgroups files-have_o_cloexec files-init
|
|
|
|
libnss_db-dbs := $(addprefix db-,\
|
|
$(filter-out hosts network key alias,\
|
|
$(databases))) \
|
|
db-initgroups
|
|
libnss_db-routines := $(libnss_db-dbs) db-open db-init hash-string
|
|
generated += $(filter-out db-alias.c db-netgrp.c, \
|
|
$(addsuffix .c,$(libnss_db-dbs)))
|
|
|
|
install-others += $(inst_vardbdir)/Makefile
|
|
|
|
# Build static module into libc if requested
|
|
libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
|
|
libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
|
|
ifeq ($(build-static-nss),yes)
|
|
routines += $(libnss_files-routines)
|
|
static-only-routines += $(libnss_files-routines)
|
|
tests-static = tst-nss-static
|
|
tests += $(tests-static)
|
|
endif
|
|
|
|
include ../Rules
|
|
|
|
ifeq (yes,$(have-selinux))
|
|
LDLIBS-makedb := -lselinux
|
|
endif
|
|
|
|
libnss-libc = $(common-objpfx)linkobj/libc.so
|
|
# Target-specific variable setting to link objects using deprecated
|
|
# RPC interfaces with the version of libc.so that makes them available
|
|
# for new links:
|
|
$(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
|
|
|
|
$(objpfx)libnss_db.so: $(objpfx)libnss_files.so
|
|
|
|
$(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
|
|
@rm -f $@.new
|
|
(echo '#define EXTERN_PARSER';\
|
|
echo '#define GENERIC "../nss_db/db-XXX.c"';\
|
|
echo '#include "$<"') > $@.new
|
|
mv -f $@.new $@
|
|
|
|
|
|
$(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
|
|
|
|
$(inst_vardbdir)/Makefile: db-Makefile $(+force)
|
|
$(do-install)
|
|
|
|
libof-nss_test1 = extramodules
|
|
$(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
|
|
$(build-module)
|
|
ifdef libnss_test1.so-version
|
|
$(objpfx)/libnss_test1.so$(libnss_test1.so-version): $(objpfx)/libnss_test1.so
|
|
$(make-link)
|
|
endif
|
|
$(objpfx)tst-nss-test1.out: $(objpfx)/libnss_test1.so$(libnss_test1.so-version)
|