[PATCH] +groups ignored

Thorsten Kukuk kukuk@suse.de
Fri Jun 27 12:20:00 GMT 2003


On Fri, Jun 27, Jakub Jelinek wrote:

> On Fri, Jun 27, 2003 at 01:20:52PM +0200, Thorsten Kukuk wrote:
> > @@ -300,13 +299,15 @@
> >        if (result->gr_name[0] == '+' && result->gr_name[1] != '\0'
> >  	  && result->gr_name[1] != '@')
> >  	{
> > +	  char buf[strlen (result->gr_name)];
> >  	  enum nss_status status;
> >  
> >  	  /* Store the group in the blacklist for the "+" at the end of
> >  	     /etc/group */
> > -	  blacklist_store_name (&result->gr_name[1], ent);
> > +	  strcpy (buf, &result->gr_name[1]);
> 
> If you already compute strlen (result->gr_name), wouldn't it be better to
> use it then (memcpy is faster than strcpy)?

Ok, here is a new patch for compat-grp.c and compat-pwd.c.

  Thorsten

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE Linux AG        Deutschherrnstr. 15-19        D-90429 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B
-------------- next part --------------
2003-06-07  Thorsten Kukuk  <kukuk@suse.de>

	* nis/nss_compat/compat-grp.c: Remove unused nis_first variable
	(getgrent_next_file) Don't store group name to early in blacklist.

	* nis/nss_compat/compat-pwd.c (internal_getpwuid_r): Save strlen
	and use  memcpy instead of strcpy.

--- nis/nss_compat/compat-grp.c
+++ nis/nss_compat/compat-grp.c	2003/06/27 12:05:06
@@ -57,14 +57,13 @@
 
 struct ent_t
 {
-  bool_t nis_first;
   bool_t files;
   FILE *stream;
   struct blacklist_t blacklist;
 };
 typedef struct ent_t ent_t;
 
-static ent_t ext_ent = {0, TRUE, NULL, {NULL, 0, 0}};
+static ent_t ext_ent = {TRUE, NULL, {NULL, 0, 0}};
 
 /* Protect global state against multiple changers.  */
 __libc_lock_define_initialized (static, lock)
@@ -300,13 +299,16 @@
       if (result->gr_name[0] == '+' && result->gr_name[1] != '\0'
 	  && result->gr_name[1] != '@')
 	{
+	  size_t len = strlen (result->gr_name);
+	  char buf[len];
 	  enum nss_status status;
 
 	  /* Store the group in the blacklist for the "+" at the end of
 	     /etc/group */
-	  blacklist_store_name (&result->gr_name[1], ent);
+	  memcpy (buf, &result->gr_name[1], len);
 	  status = getgrnam_plusgroup (&result->gr_name[1], result, ent,
 				       buffer, buflen, errnop);
+	  blacklist_store_name (buf, ent);
 	  if (status == NSS_STATUS_SUCCESS)	/* We found the entry. */
 	    break;
 	  else if (status == NSS_STATUS_RETURN	/* We couldn't parse the entry */
@@ -468,7 +470,7 @@
 _nss_compat_getgrnam_r (const char *name, struct group *grp,
 			char *buffer, size_t buflen, int *errnop)
 {
-  ent_t ent = {0, TRUE, NULL, {NULL, 0, 0}};
+  ent_t ent = {TRUE, NULL, {NULL, 0, 0}};
   enum nss_status result;
 
   if (name[0] == '-' || name[0] == '+')
@@ -590,7 +592,7 @@
 _nss_compat_getgrgid_r (gid_t gid, struct group *grp,
 			char *buffer, size_t buflen, int *errnop)
 {
-  ent_t ent = {0, TRUE, NULL, {NULL, 0, 0}};
+  ent_t ent = {TRUE, NULL, {NULL, 0, 0}};
   enum nss_status result;
 
   __libc_lock_lock (lock);
--- nis/nss_compat/compat-pwd.c
+++ nis/nss_compat/compat-pwd.c	2003/06/27 12:12:36
@@ -585,12 +585,13 @@
       if (result->pw_name[0] == '+' && result->pw_name[1] != '\0'
 	  && result->pw_name[1] != '@')
 	{
-	  char buf[strlen (result->pw_name)];
+	  size_t len = strlen (result->pw_name);
+	  char buf[len];
 	  enum nss_status status;
 
 	  /* Store the User in the blacklist for the "+" at the end of
 	     /etc/passwd */
-	  strcpy (buf, &result->pw_name[1]);
+	  memcpy (buf, &result->pw_name[1], len);
 	  status = getpwnam_plususer (&result->pw_name[1], result, ent,
 				      buffer, buflen, errnop);
 	  blacklist_store_name (buf, ent);
@@ -939,10 +940,12 @@
       if (result->pw_name[0] == '-' && result->pw_name[1] == '@'
 	  && result->pw_name[2] != '\0')
 	{
-	  char buf[strlen (result->pw_name)];
+	  /* -1, because we remove first two character of pw_name.  */
+	  size_t len = strlen (result->pw_name) - 1;
+	  char buf[len];
 	  enum nss_status status;
 
-	  strcpy (buf, &result->pw_name[2]);
+	  memcpy (buf, &result->pw_name[2], len);
 
 	  status = getpwuid_plususer (uid, result, buffer, buflen, errnop);
 	  if (status == NSS_STATUS_SUCCESS &&
@@ -956,10 +959,12 @@
       if (result->pw_name[0] == '+' && result->pw_name[1] == '@'
 	  && result->pw_name[2] != '\0')
 	{
-	  char buf[strlen (result->pw_name)];
+	  /* -1, because we remove first two characters of pw_name.  */
+	  size_t len = strlen (result->pw_name) - 1;
+	  char buf[len];
 	  enum nss_status status;
 
-	  strcpy (buf, &result->pw_name[2]);
+	  memcpy (buf, &result->pw_name[2], len);
 
 	  status = getpwuid_plususer (uid, result, buffer, buflen, errnop);
 
@@ -983,10 +988,11 @@
       if (result->pw_name[0] == '-' && result->pw_name[1] != '\0'
 	  && result->pw_name[1] != '@')
 	{
-	  char buf[strlen (result->pw_name)];
+	  size_t len = strlen (result->pw_name);
+	  char buf[len];
 	  enum nss_status status;
 
-	  strcpy (buf, &result->pw_name[1]);
+	  memcpy (buf, &result->pw_name[1], len);
 
 	  status = getpwuid_plususer (uid, result, buffer, buflen, errnop);
 	  if (status == NSS_STATUS_SUCCESS &&
@@ -999,10 +1005,11 @@
       if (result->pw_name[0] == '+' && result->pw_name[1] != '\0'
 	  && result->pw_name[1] != '@')
 	{
-	  char buf[strlen (result->pw_name)];
+	  size_t len = strlen (result->pw_name);
+	  char buf[len];
 	  enum nss_status status;
 
-	  strcpy (buf, &result->pw_name[1]);
+	  memcpy (buf, &result->pw_name[1], len);
 
 	  status = getpwuid_plususer (uid, result, buffer, buflen, errnop);
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20030627/c794d0a6/attachment.sig>


More information about the Libc-alpha mailing list