public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] innetgr fixes
@ 2005-09-24 19:02 Jakub Jelinek
  2005-09-25 22:55 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2005-09-24 19:02 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

Two problems:
1) there is a memory leak - if result != 0 (-1 means allocation failure,
1 that we found the netgroup entry we are looking for), innetgr did not call
endnetgrent hook, so resources in the NSS module weren't freed.
2) innetgr return value is supposed to be 1 for match and 0 for non-match
or error (from info libc):
     The return value is `1' if an entry matching the given triple is
     found in the netgroup.  The return value is `0' if the netgroup
     itself is not found, the netgroup does not contain the triple or
     internal errors occurred.
result variable internally is 0 for non-match, 1 for match and -1 for
internal error (the distinction is needed to find out if the loop should
continue), so return result == 1; which is what getnetgrent_r.c used
until August last year is IMHO correct.

2005-09-24  Jakub Jelinek  <jakub@redhat.com.

	* inet/getnetgrent_r.c (innetgr): Call endfct even if result != 0.
	Return 1 only if result == 1.  Patch by Benoit Capelle.

--- libc/inet/getnetgrent_r.c.jj	2005-09-12 09:20:29.000000000 +0200
+++ libc/inet/getnetgrent_r.c	2005-09-24 20:53:51.000000000 +0200
@@ -409,9 +409,6 @@ innetgr (const char *netgroup, const cha
 		    }
 		}
 
-	      if (result != 0)
-		break;
-
 	      /* If we found one service which does know the given
 		 netgroup we don't try further.  */
 	      status = NSS_STATUS_RETURN;
@@ -422,6 +419,9 @@ innetgr (const char *netgroup, const cha
 	  if (endfct != NULL)
 	    (*endfct) (&entry);
 
+	  if (result != 0)
+	    break;
+
 	  /* Look for the next service.  */
 	  no_more = __nss_next (&entry.nip, "setnetgrent",
 				&setfct.ptr, status, 0);
@@ -444,6 +444,6 @@ innetgr (const char *netgroup, const cha
   /* Free the memory.  */
   free_memory (&entry);
 
-  return result;
+  return result == 1;
 }
 libc_hidden_def (innetgr)

	Jakub

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

* Re: [PATCH] innetgr fixes
  2005-09-24 19:02 [PATCH] innetgr fixes Jakub Jelinek
@ 2005-09-25 22:55 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2005-09-25 22:55 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

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

Applied.

-- 
➧ 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-09-25 22:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-24 19:02 [PATCH] innetgr fixes Jakub Jelinek
2005-09-25 22:55 ` 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).