* lib/gshadow.c: Removed limitation on the length of the gshadow

lines.
	* lib/gshadow.c: Compare the result of fgetsx() with the provided
	buffer instead of NULL.
This commit is contained in:
nekral-guest 2009-06-12 17:50:24 +00:00
parent fa69d08d13
commit ae00a3579c
2 changed files with 59 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2009-06-11 Nicolas François <nicolas.francois@centraliens.net>
* lib/gshadow.c: Removed limitation on the length of the gshadow
lines.
* lib/gshadow.c: Compare the result of fgetsx() with the provided
buffer instead of NULL.
2009-06-11 Nicolas François <nicolas.francois@centraliens.net> 2009-06-11 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetgrnam.c, * libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetgrnam.c,

View File

@ -2,7 +2,7 @@
* Copyright (c) 1990 - 1994, Julianne Frances Haugh * Copyright (c) 1990 - 1994, Julianne Frances Haugh
* Copyright (c) 1996 - 1998, Marek Michałkiewicz * Copyright (c) 1996 - 1998, Marek Michałkiewicz
* Copyright (c) 2005 , Tomasz Kłoczko * Copyright (c) 2005 , Tomasz Kłoczko
* Copyright (c) 2008 , Nicolas François * Copyright (c) 2008 - 2009, Nicolas François
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -41,7 +41,6 @@
#include "prototypes.h" #include "prototypes.h"
#include "defines.h" #include "defines.h"
static /*@null@*/FILE *shadow; static /*@null@*/FILE *shadow;
static char sgrbuf[BUFSIZ * 4];
static /*@null@*//*@only@*/char **members = NULL; static /*@null@*//*@only@*/char **members = NULL;
static size_t nmembers = 0; static size_t nmembers = 0;
static /*@null@*//*@only@*/char **admins = NULL; static /*@null@*//*@only@*/char **admins = NULL;
@ -131,12 +130,25 @@ void endsgent (void)
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *string) /*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *string)
{ {
static char *sgrbuf = NULL;
static size_t sgrbuflen = 0;
char *fields[FIELDS]; char *fields[FIELDS];
char *cp; char *cp;
int i; int i;
size_t len = strlen (string) + 1;
strncpy (sgrbuf, string, sizeof sgrbuf - 1); if (len > sgrbuflen) {
sgrbuf[sizeof sgrbuf - 1] = '\0'; char *buf = (char *) realloc (sgrbuf, sizeof (char) * len);
if (NULL == buf) {
return NULL;
}
sgrbuf = buf;
sgrbuflen = len;
}
strncpy (sgrbuf, string, len);
sgrbuf[len-1] = '\0';
cp = strrchr (sgrbuf, '\n'); cp = strrchr (sgrbuf, '\n');
if (NULL != cp) { if (NULL != cp) {
@ -161,7 +173,7 @@ void endsgent (void)
* the line is invalid. * the line is invalid.
*/ */
if ((NULL != cp) || (i != FIELDS)) if ((NULL != cp) || (i != FIELDS)) {
#ifdef USE_NIS #ifdef USE_NIS
if (!IS_NISCHAR (fields[0][0])) { if (!IS_NISCHAR (fields[0][0])) {
return 0; return 0;
@ -171,6 +183,7 @@ void endsgent (void)
#else #else
return 0; return 0;
#endif #endif
}
sgroup.sg_name = fields[0]; sgroup.sg_name = fields[0];
sgroup.sg_passwd = fields[1]; sgroup.sg_passwd = fields[1];
@ -199,20 +212,48 @@ void endsgent (void)
/*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE * fp) /*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE * fp)
{ {
char buf[sizeof sgrbuf]; static size_t buflen = 0;
static char *buf = NULL;
char *cp; char *cp;
struct sgrp *ret;
if (0 == buflen) {
buf = (char *) malloc (BUFSIZ);
if (NULL == buf) {
return NULL;
}
}
if (NULL == fp) { if (NULL == fp) {
return (0); return NULL;
} }
#ifdef USE_NIS #ifdef USE_NIS
while (fgetsx (buf, (int) sizeof buf, fp) != (char *) 0) while (fgetsx (buf, (int) sizeof buf, fp) == buf)
#else #else
if (fgetsx (buf, (int) sizeof buf, fp) != (char *) 0) if (fgetsx (buf, (int) sizeof buf, fp) == buf)
#endif #endif
{ {
cp = strchr (buf, '\n'); while ( ((cp = strrchr (buf, '\n')) == NULL)
&& (feof (fp) == 0)) {
size_t len;
cp = (char *) realloc (buf, buflen*2);
if (NULL == cp) {
return NULL;
}
buf = cp;
buflen *= 2;
len = strlen (buf);
if (fgetsx (&buf[len],
(int) (buflen - len),
fp) != &buf[len]) {
return NULL;
}
}
cp = strrchr (buf, '\n');
if (NULL != cp) { if (NULL != cp) {
*cp = '\0'; *cp = '\0';
} }
@ -223,7 +264,7 @@ void endsgent (void)
#endif #endif
return (sgetsgent (buf)); return (sgetsgent (buf));
} }
return 0; return NULL;
} }
/* /*
@ -235,7 +276,6 @@ void endsgent (void)
#ifdef USE_NIS #ifdef USE_NIS
bool nis_1_group = false; bool nis_1_group = false;
struct sgrp *val; struct sgrp *val;
char buf[BUFSIZ];
#endif #endif
if (NULL == shadow) { if (NULL == shadow) {
setsgent (); setsgent ();
@ -334,7 +374,6 @@ void endsgent (void)
struct sgrp *sgrp; struct sgrp *sgrp;
#ifdef USE_NIS #ifdef USE_NIS
char buf[BUFSIZ];
static char save_name[16]; static char save_name[16];
int nis_disabled = 0; int nis_disabled = 0;
#endif #endif