This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug nis/10203] New: NIS setpwent/getpwent/endpwent memory leak

When the name server switch gets configured for NIS:

passwd: nis files

and the password map is larger than MINSIZE, _nis_saveit in
nis/nss_nis/nis-pwd.c allocates linked blocks with intern.start pointing at the
first block. internal_nis_setpwent() initially sets to intern.start.
Currently, internal_nis_endpwent() uses as the starting block to
iterate over the chain when free'ing blocks.

When getpwent() gets called, however, can be reset to another block
in the chain. As a result, the following program will cause allocated blocks to
be never be free'd since in this case points at the last block and
the "next" pointer on this block is set to NULL.

#include <stdio.h>
#include <malloc.h>
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>

main(int argc, char *argv[])
   struct passwd *entry;


   entry = getpwent();
   while (entry != NULL) {
      entry = getpwent();


   return 0;

After internal_nis_endpwent(), sets and intern.start to NULL, the
other allocated blocks on the chain are irretrievably lost. This issue exists in
other releases prior to glibc-2.10, including glibc-2.5 on RHEL 5.3.

The easiest fix is to make internal_nis_endpwent() use intern.start directly
instead of

diff -urNp a/nis/nss_nis/nis-pwd.c b/nis/nss_nis/nis-pwd.c
--- a/nis/nss_nis/nis-pwd.c     2006-05-01 15:31:15.000000000 -0700
+++ b/nis/nss_nis/nis-pwd.c     2009-05-26 12:55:09.000000000 -0700
@@ -116,7 +116,7 @@ internal_nis_endpwent (void)
       oldkeylen = 0;
-  struct response_t *curr =;
+  struct response_t *curr = intern.start;
   while (curr != NULL)



           Summary: NIS setpwent/getpwent/endpwent  memory leak
           Product: glibc
           Version: 2.10
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nis
        AssignedTo: kukuk at suse dot de
        ReportedBy: jlanders at vmware dot com
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: x86_64-linuxnptl
  GCC host triplet: x86_64-linuxnptl
GCC target triplet: x86_64-linuxnptl

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]