[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#520744: _SC_GETGR_R_SIZE_MAX returned on amd64 too small



retitle 520744  _SC_GETGR_R_SIZE_MAX returned on amd64 too small
user debian-amd64@lists.debian.org 
usertag 520744 debian-amd64 
thanks

Hi,
attached testcase shows that the buffersize for getgrent_r returned via
sysconf(_SC_GETGR_R_SIZE_MAX) is too small on amd64. Using the returned
1024 byetes results in ERANGE. i386 and ppc also use 1024 bytes which
works fine.
While returning -1 is from sysconf is o.k., a too low value certainly is
not. Can this be fixed in a Lenny point release since it might break
arbitrary software on this architecture?
Cheers,
 -- Guido
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>

int main()
{
   int max;
   char *buf;
   struct group grpdata, *grp;
   char *unix_sock_group = strdup("libvirt");

   max = sysconf(_SC_GETGR_R_SIZE_MAX);
   printf("buffer size from sysconf: %d\n", max);
   buf = malloc(max);
   if (!buf) {
	printf("Can't allocate buffer\n");
        return 1;
   }

   while (1) {
	int ret;

   	ret = getgrnam_r(unix_sock_group, &grpdata, buf, max, &grp);
        if (ret == ERANGE) {
		free(buf);
		max *= 2;
		buf = malloc(max);
   		if (!buf) {
			printf("Can't allocate buffer\n");
        		return 1;
   		}
		printf("Increased buffert to %d\n", max);
		continue;
	}
   	if (ret != 0 || grp == NULL) {
		fprintf(stderr, "Cannot resolve group\n");
		if (ret)
			fprintf(stderr, "%s (%d)\n", strerror(ret), ret);
		return 1;
   	} else {
		printf("gid: %d\n", grp->gr_gid);
		return 0;
	}
   }
   return 0;
}

Reply to: