public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] nss_compat and buffer size handling
@ 2005-07-05 20:51 Thorsten Kukuk
  2005-07-06 21:06 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Kukuk @ 2005-07-05 20:51 UTC (permalink / raw)
  To: libc-hacker


Hi,

nss_compat doesn't preserve the correct return value in one place.
As result a "entry not found" error is returned instead of "buffer
too small". And in one place we missed a check, if the dlopened module
provides a getgrgid_r function:

2005-07-05  Thorsten Kukuk  <kukuk@suse.de>

	* nis/nss_compat/compat-grp.c (internal_getgrgid_r): Check if NSS
	module provides getgrgid_r.
	(getgrnam_plusgroup): Preserve original return value.

	* nis/nss_compat/compat-pwd.c (getpwnam_plususer): Preserve
	original return value.
	* nis/nss_compat/compat-spwd.c (getspnam_plususer): Likewise.

--- nis/nss_compat/compat-grp.c	12 Sep 2004 20:38:05 -0000	1.29
+++ nis/nss_compat/compat-grp.c	5 Jul 2005 13:27:28 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2003,2004,2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -226,12 +226,14 @@
 getgrnam_plusgroup (const char *name, struct group *result, ent_t *ent,
 		    char *buffer, size_t buflen, int *errnop)
 {
+  enum nss_status status;
+
   if (!nss_getgrnam_r)
     return NSS_STATUS_UNAVAIL;
 
-  if (nss_getgrnam_r (name, result, buffer, buflen, errnop) !=
+  if ((status = nss_getgrnam_r (name, result, buffer, buflen, errnop)) !=
       NSS_STATUS_SUCCESS)
-    return NSS_STATUS_NOTFOUND;
+    return status;
 
   if (in_blacklist (result->gr_name, strlen (result->gr_name), ent))
     return NSS_STATUS_NOTFOUND;
@@ -551,7 +553,7 @@
 	     !(parse_res = _nss_files_parse_grent (p, result, data, buflen,
 						   errnop)));
 
-      if (parse_res == -1)
+      if (__builtin_expect (parse_res == -1, 0))
 	/* The parser ran out of space.  */
 	goto erange_reset;
 
@@ -591,6 +593,9 @@
 	{
 	  enum nss_status status;
 
+	  if (!nss_getgrgid_r)
+	    return NSS_STATUS_UNAVAIL;
+
 	  status = nss_getgrgid_r (gid, result, buffer, buflen, errnop);
 	  if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
 	    return NSS_STATUS_NOTFOUND;
--- nis/nss_compat/compat-pwd.c	12 Sep 2004 20:38:05 -0000	1.34
+++ nis/nss_compat/compat-pwd.c	5 Jul 2005 13:27:28 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2003,2004,2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -453,6 +453,7 @@
 getpwnam_plususer (const char *name, struct passwd *result, ent_t *ent,
 		   char *buffer, size_t buflen, int *errnop)
 {
+  enum nss_status status;
   struct passwd pwd;
   char *p;
   size_t plen;
@@ -473,9 +474,9 @@
   p = buffer + (buflen - plen);
   buflen -= plen;
 
-  if (nss_getpwnam_r (name, result, buffer, buflen, errnop) !=
+  if ((status = nss_getpwnam_r (name, result, buffer, buflen, errnop)) !=
       NSS_STATUS_SUCCESS)
-    return NSS_STATUS_NOTFOUND;
+    return status;
 
   if (in_blacklist (result->pw_name, strlen (result->pw_name), ent))
     return NSS_STATUS_NOTFOUND;
--- nis/nss_compat/compat-spwd.c	12 Sep 2004 20:38:05 -0000	1.27
+++ nis/nss_compat/compat-spwd.c	5 Jul 2005 13:27:28 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2003,2004,2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -401,6 +401,7 @@
 getspnam_plususer (const char *name, struct spwd *result, ent_t *ent,
 		   char *buffer, size_t buflen, int *errnop)
 {
+  enum nss_status status;
   struct spwd pwd;
   char *p;
   size_t plen;
@@ -425,9 +426,9 @@
   p = buffer + (buflen - plen);
   buflen -= plen;
 
-  if (nss_getspnam_r (name, result, buffer, buflen, errnop) !=
+  if ((status = nss_getspnam_r (name, result, buffer, buflen, errnop)) !=
       NSS_STATUS_SUCCESS)
-    return NSS_STATUS_NOTFOUND;
+    return status;
 
   if (in_blacklist (result->sp_namp, strlen (result->sp_namp), ent))
     return NSS_STATUS_NOTFOUND;

-- 
Thorsten Kukuk         http://www.suse.de/~kukuk/      kukuk@suse.de
SUSE LINUX Products GmbH       Maxfeldstr. 5       D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nss_compat and buffer size handling
  2005-07-05 20:51 [PATCH] nss_compat and buffer size handling Thorsten Kukuk
@ 2005-07-06 21:06 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2005-07-06 21:06 UTC (permalink / raw)
  To: Thorsten Kukuk; +Cc: libc-hacker

[-- Attachment #1: Type: text/plain, Size: 128 bytes --]

Applied with some cosmetic changes.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-07-06 21:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-05 20:51 [PATCH] nss_compat and buffer size handling Thorsten Kukuk
2005-07-06 21:06 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).