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

[aj@arthur.rhein-neckar.de: Re: libc/430: getservbyname (name, NULL) not working]



Hi all, here is the response I got from Andreas regarding the libc6
bug I found.  Summing up the problem, getservbyname chokes if it is
passed NULL as the proto, which should be a valid option.  Here is his
email and the patches.  Maybe I should have just sent this to Dale,
but I figure that it may be of interest to others as well.

Ciao,

-----Forwarded message from Andreas Jaeger <aj@arthur.rhein-neckar.de>-----

Return-Path: <aj@arthur.rhein-neckar.de>
Received: from gate.cks.com ([209.116.197.20]) by heorot.cks.com
	 with esmtp (ident davidw using rfc1413) id m0xwt2a-000AFgC
	(Debian Smail-3.2 1996-Jul-4 #2); Mon, 26 Jan 1998 10:13:48 -0800 (PST)
Received: from birdland.rhein-neckar.de (root@birdland.rhein-neckar.de [193.197.88.3]) by gate.cks.com (8.8.5/8.7.3) with ESMTP id KAA11259 for <davidw@gate.cks.com>; Mon, 26 Jan 1998 10:15:02 -0800 (PST)
Received: from amalthea.rhein-neckar.de (uucp@localhost) by birdland.rhein-neckar.de (8.8.7/8.8.3) with bsmtp id TAA23467; Mon, 26 Jan 1998 19:00:08 +0100 (MET)
Received: from arthur.rhein-neckar.de by amalthea.rhein-neckar.de
	via rsmtp with bsmtp
	id <m0xwsYy-00000aC@amalthea.rhein-neckar.de>
	for <bugs@gnu.org>; Mon, 26 Jan 1998 18:43:12 +0100 (MET)
	(Smail-3.2 1996-Jul-4 #5 built 1997-Jun-26)
Received: by arthur.rhein-neckar.de
	via sendmail with stdio
	id <m0xwsWw-0001wRC@arthur.rhein-neckar.de>
	for bugs@gnu.org; Mon, 26 Jan 1998 18:41:06 +0100 (CET)
	(Smail-3.2.0.95 1997-May-7 #5 built 1997-May-28)
Message-Id: <m0xwsWw-0001wRC@arthur.rhein-neckar.de>
Date: Mon, 26 Jan 1998 18:41:06 +0100 (CET)
From: Andreas Jaeger <aj@arthur.rhein-neckar.de>
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
To: David Welton <davidw@gate.cks.com>
Reply-To: bugs@gnu.org
CC: bugs@gnu.org
Subject: Re: libc/430: getservbyname (name, NULL) not working
X-Mailer: VM 6.34 under 20.3 "Vatican City" XEmacs  Lucid
Content-Type: text/plain; charset=us-ascii
X-UIDL: ef7bbefc8ab2692db83787cf8df020e4


Hi David,

the following patches have been made which should correct the
problem. Please recreate all db files since the internal structure of
db had to be changed!

Could you please apply this patch and tell me if now everything works
for you?
Andreas

1998-01-25 19:39  Ulrich Drepper  <drepper@cygnus.com>

	* db/makedb.c (process_input): Write terminating \0 for value.
	(print_database): Simply print value string, don't use length.

1998-01-24 15:13  Ulrich Drepper  <drepper@happy.cygnus.com> 

        * nss/db-Makefile: Handle empty and comment lines better.
        ($(VAR_DB)/services.db): Generate entries with missing protocol
        value.
         
1998-01-23  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

        * nss/nss_files/files-service.c (getservbyport): Allow proto ==
          NULL.
          (getservbyname): Allow proto == NULL.
          Pointed out by David N. Welton <davidw@gate.cks.com>.
          [PR libc/430].

--- libc-2.0.6/nss/db-Makefile	Sat Jan 17 09:40:37 1998
+++ libc/nss/db-Makefile	Sat Jan 24 16:59:30 1998
@@ -32,6 +32,8 @@
 $(VAR_DB)/passwd.db: /etc/passwd
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { printf ".%s ", $$1; print; \
 			   printf "=%s ", $$3; print }' $^ | \
@@ -41,6 +43,8 @@
 $(VAR_DB)/group.db: /etc/group
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { printf ".%s ", $$1; print; \
 			   printf "=%s ", $$3; print }' $^ | \
@@ -50,6 +54,8 @@
 $(VAR_DB)/ethers.db: /etc/ethers
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { printf ".%s ", $$1; print; \
 			   printf "=%s ", $$2; print }' $^ | \
@@ -59,6 +65,8 @@
 $(VAR_DB)/protocols.db: /etc/protocols
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { printf ".%s ", $$1; print; \
 			   printf "=%s ", $$2; print; \
@@ -70,6 +78,8 @@
 $(VAR_DB)/rpc.db: /etc/rpc
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { printf ".%s ", $$1; print; \
 			   printf "=%s ", $$2; print; \
@@ -81,17 +91,24 @@
 $(VAR_DB)/services.db: /etc/services
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { FS="[ \t/]+"; cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { printf ".%s/%s ", $$1, $$3; print; \
+			   printf ".%s/ ", $$1; print; \
 			   printf "=%s/%s ", $$2, $$3; print; \
+			   printf "=%s/ ", $$2; print; \
 			   for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \
-			     { printf ".%s/%s ", $$i, $$3; print } }' $^ | \
+			     { printf ".%s/%s ", $$i, $$3; print; \
+			       printf ".%s/ ", $$i; print } }' $^ | \
 	$(MAKEDB) -o $@ -
 	@echo "done."
 
 $(VAR_DB)/shadow.db: /etc/shadow
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
 	$(MAKEDB) -o $@ -
@@ -100,6 +117,8 @@
 $(VAR_DB)/netgroup.db: /etc/netgroup
 	@echo -n "$(patsubst %.db,%,$(@F))... "
 	@$(AWK) 'BEGIN { cnt=0 } \
+		 /^[ \t]*$$/ { next } \
+		 /^[ \t]*#/ { next } \
 		 { printf "0%u ", cnt++; print } \
 		 /^[^#]/ { end=sub(/\\/, " "); \
 			   gsub(/[ \t]+/, " "); \

--- libc-2.0.6/nss/nss_files/files-service.c.~1~	Sat Jan 17 09:40:37 1998
+++ libc/nss/nss_files/files-service.c	Sat Jan 24 16:59:30 1998
@@ -39,8 +39,8 @@
 
 #include GENERIC
 
-DB_LOOKUP (servbyname, 2 + strlen (name) + strlen (proto),
-	   (".%s/%s", name, proto),
+DB_LOOKUP (servbyname, 2 + strlen (name) + (proto ? strlen (proto) : 0),
+	   (".%s/%s", name, proto ?: ""),
 	   {
 	     /* Must match both protocol (if specified) and name.  */
 	     if (proto != NULL && strcmp (result->s_proto, proto))
@@ -49,10 +49,12 @@
 	   },
 	   const char *name, const char *proto)
 
-DB_LOOKUP (servbyport, 20 + strlen (proto), ("=%d/%s", port, proto),
+DB_LOOKUP (servbyport, 21 + (proto ? strlen (proto) : 0),
+	   ("=%d/%s", ntohs(port), proto ?: ""),
 	   {
 	     /* Must match both port and protocol.  */
-	     if (result->s_port == port
-		 && strcmp (result->s_proto, proto) == 0)
+	     if (result->s_port == ntohs (port)
+		 && (proto == NULL
+		     || strcmp (result->s_proto, proto) == 0))
 	       break;
 	   }, int port, const char *proto)

Index: db/makedb.c
===================================================================
RCS file: /opt/cvsroot/glibc2.0/db/makedb.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 makedb.c
--- db/makedb.c	1998/01/17 08:22:38	1.1.1.1
+++ db/makedb.c	1998/01/26 09:14:15
@@ -1,5 +1,5 @@
 /* makedb -- create simple DB database from textual input.
-   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -121,7 +121,7 @@
 Copyright (C) %s Free Software Foundation, Inc.\n\
 This is free software; see the source for copying conditions.  There is NO\n\
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "1996, 1997");
+"), "1996, 1997, 1998");
       printf (_("Written by %s.\n"), "Ulrich Drepper");
 
       exit (EXIT_SUCCESS);
@@ -186,7 +186,8 @@
   db_file = dbopen (output_name, O_CREAT | O_RDWR | O_TRUNC, 0666,
 		    DB_BTREE, NULL);
   if (db_file == NULL)
-    error (EXIT_FAILURE, errno, gettext ("cannot open output file `%s'"));
+    error (EXIT_FAILURE, errno, gettext ("cannot open output file `%s'"),
+	   output_name);
 
   /* Start the real work.  */
   status = process_input (input_file, input_name, db_file, to_lowercase,
@@ -298,7 +299,7 @@
 	++cp;
 
       val.data = cp;
-      val.size = &line[n] - cp;
+      val.size = (&line[n] - cp) + 1;
 
       /* Store the value.  */
       status = output->put (output, &key, &val, R_NOOVERWRITE);
@@ -311,11 +312,12 @@
 			       gettext ("duplicate key"));
 	      /* This is no real error.  Just give a warning.  */
 	      status = 0;
+	      continue;
 	    }
 	  else
-	    error (0, errno, gettext ("while writing data base file"));
+	    error (0, errno, gettext ("while writing database file"));
 
-	  status = status ? EXIT_FAILURE : EXIT_SUCCESS;
+	  status = EXIT_FAILURE;
 
 	  clearerr (input);
 	  break;
@@ -324,7 +326,7 @@
 
   if (ferror (input))
     {
-      error (0, 0, gettext ("problems while reading `%s'"));
+      error (0, 0, gettext ("problems while reading `%s'"), inname);
       status = EXIT_FAILURE;
     }
 
@@ -343,7 +345,7 @@
   no_more = db->seq (db, &key, &val, R_FIRST);
   while (!no_more)
     {
-      printf ("%.*s %.*s\n", (int) key.size, (char *) key.data, (int) val.size,
+      printf ("%.*s %s\n", (int) key.size, (char *) key.data,
 	      (char *) val.data);
 
       no_more = db->seq (db, &key, &val, R_NEXT);

-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@alma.student.uni-kl.de


-----End of forwarded message-----

-- 
David Welton                          http://www.efn.org/~davidw 

	Debian GNU/Linux - www.debian.org

Attachment: pgpMRNW1hMDcQ.pgp
Description: PGP signature


Reply to: