This is the mail archive of the libc-hacker@sourceware.cygnus.com 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]

Re: getXXent.c endless loop



> 
> Thorsten Kukuk <kukuk@weber-eb.uni-paderborn.de> writes:
> 
> > With all backends. The problem is, that there is no error. We have no
> > more entrys, and returns. But errno is set to ERANGE from an earlier
> > to small buffer, and getXXent thinks we need more memory.
> 
> errno should always be set.  I have only looked at the 2.1 sources and
> here for files/db which seem to be ok.

No, the 2.1 sources are not ok, and they are for files/db not ok, too.
I haven't tested or looked at 2.0.

Try the following: Make sure, that all lines are in /etc/group are
shorter then 600 bytes. Then add a new line at the end, which is
700 bytes long. Call setgrent/getgrent/endgrent and let you show all
entries. After displaying the last entry (which is bigger then 622 bytes,
so you need to allocate a bigger buffer first), errno is set to ERANGE.
The next getgrent_r calls fails, because there are no more entries.
But getXXent.c sees errno == ERANGE and allocates new memory. And here
is the loop, which leave until we have no more memory.

I have append my testprogram. Call it with this service as 
parameter, which you wish to test, for example getgrent files
or getgrent compat.

  Thorsten

-- 
Thorsten Kukuk  kukuk@vt.uni-paderborn.de
                http://www-vt.uni-paderborn.de/~kukuk
Linux is like a Vorlon.  It is incredibly powerful, gives terse,
cryptic answers and has a lot of things going on in the background.

#include <nss.h>
#include <grp.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

int
main(int argc, char **argv)
{
  struct group *grp;

  if (argc > 1)
    if (__nss_configure_lookup ("group", argv[1]) != 0)
    	printf ("__nss_configure_lookup (\"group\", \"%s\") fails: %s\n",
    		argv[1], strerror(errno));

  setgrent();

  while ((grp=getgrent())!=NULL)
    {
      int i;

      printf ("%s:%s:%d:", grp->gr_name, grp->gr_passwd, grp->gr_gid);
      i =  0;
      while (grp->gr_mem[i] != NULL)
	{
	  if (i != 0)
	    printf (",");
	  printf ("%s", grp->gr_mem[i]);
	  i++;
	}
      printf ("\n");
    }

  endgrent();

  return 0;
}


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