summary refs log tree commit diff
path: root/nis/nss_nisplus/nisplus-parser.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-03-08 11:46:22 +0000
committerUlrich Drepper <drepper@redhat.com>1999-03-08 11:46:22 +0000
commit7d1de115db4c8b660d12ad1a72cb95ffa7f7a234 (patch)
treeca94f7d2b4d2e78a93ae8e653cd5ab5528fab2ed /nis/nss_nisplus/nisplus-parser.c
parentb74656f98231fc1d31f8200b3306e2d821ec2cf4 (diff)
downloadglibc-7d1de115db4c8b660d12ad1a72cb95ffa7f7a234.tar.gz
glibc-7d1de115db4c8b660d12ad1a72cb95ffa7f7a234.tar.xz
glibc-7d1de115db4c8b660d12ad1a72cb95ffa7f7a234.zip
Update.
1999-03-08  Andreas Schwab  <schwab@issan.cs.uni-dortmund.de>

	* sysdeps/unix/sysv/linux/ttyname.c (ttyname): Undo last change.
	/dev/pts status may change during runtime.

1999-03-08  Andreas Schwab  <schwab@issan.cs.uni-dortmund.de>

	* sysdeps/unix/sysv/linux/ttyname_r.c (__ttyname_r): Undo last
	change.  /dev/pts status can change during runtime.

1999-03-07  Thorsten Kukuk  <kukuk@suse.de>

	* sunrpc/svc_tcp.c (readtcp): go into fatal error state if
	poll reports error.
	* nis/nss_nisplus/nisplus-parser.c: Avoid duplicate strlen calls,
	add some more sanity checks.
	* nis/nss_nisplus/nisplus-pwd.c: Include nisplus-parser.h for
	parser prototype.

1999-03-05  Thorsten Kukuk  <kukuk@suse.de>

	* sunrpc/rpc/xdr.h: Add x_getint32/x_putint32 to xdr_ops,
	change XDR_GETINT32/XDR_PUTINT32 to sue new functions.
	* sunrpc/xdr_mem.c: Add xdrmem_getint32, xdrmem_putint32.
	* sunrpc/xdr_rec.c: Add xdrrec_getint32, xdrrec_putint32.
	* sunrpc/xdr_sizeof.c: Add x_putint32, add dummy function
	for x_getint32.
	* sunrpc/xdr_stdio.c: Add xdrstdio_getint32, xdrstdio_putint32.
	* nis/nis_print.c: Fix ctime argument for platforms where
	sizeof (time_t) != sizeof (int).

	255.  Patch by Bruno Haible <haible@ilog.fr> [PR libc/1010].
Diffstat (limited to 'nis/nss_nisplus/nisplus-parser.c')
-rw-r--r--nis/nss_nisplus/nisplus-parser.c78
1 files changed, 53 insertions, 25 deletions
diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c
index fa4073e6d8..35b8a2881e 100644
--- a/nis/nss_nisplus/nisplus-parser.c
+++ b/nis/nss_nisplus/nisplus-parser.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -38,6 +38,7 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
 {
   char *first_unused = buffer;
   size_t room_left = buflen;
+  size_t len;
 
   if (result == NULL)
     return 0;
@@ -61,9 +62,12 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
   strncpy (first_unused, NISENTRYVAL (0, 0, result),
 	   NISENTRYLEN (0, 0, result));
   first_unused[NISENTRYLEN (0, 0, result)] = '\0';
+  len = strlen (first_unused);
+  if (len == 0) /* No name ? Should never happen, database is corrupt */
+    return 0;
   pw->pw_name = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN (0, 1, result) >= room_left)
     goto no_more_room;
@@ -72,8 +76,9 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
 	   NISENTRYLEN (0, 1, result));
   first_unused[NISENTRYLEN (0, 1, result)] = '\0';
   pw->pw_passwd = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  len = strlen (first_unused);
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN(0, 2, result) >= room_left)
     goto no_more_room;
@@ -81,9 +86,12 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
   strncpy (first_unused, NISENTRYVAL (0, 2, result),
 	   NISENTRYLEN (0, 2, result));
   first_unused[NISENTRYLEN (0, 2, result)] = '\0';
+  len = strlen (first_unused);
+  if (len == 0) /* If we don't have a uid, it's an invalid shadow entry */
+    return 0;
   pw->pw_uid = atoi (first_unused);
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN (0, 3, result) >= room_left)
     goto no_more_room;
@@ -91,9 +99,12 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
   strncpy (first_unused, NISENTRYVAL (0, 3, result),
 	   NISENTRYLEN (0, 3, result));
   first_unused[NISENTRYLEN (0, 3, result)] = '\0';
+  len = strlen (first_unused);
+  if (len == 0) /* If we don't have a gid, it's an invalid shadow entry */
+    return 0;
   pw->pw_gid = atoi (first_unused);
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN(0, 4, result) >= room_left)
     goto no_more_room;
@@ -102,8 +113,9 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
 	   NISENTRYLEN (0, 4, result));
   first_unused[NISENTRYLEN (0, 4, result)] = '\0';
   pw->pw_gecos = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  len = strlen (first_unused);
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN (0, 5, result) >= room_left)
     goto no_more_room;
@@ -112,8 +124,9 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
 	   NISENTRYLEN (0, 5, result));
   first_unused[NISENTRYLEN (0, 5, result)] = '\0';
   pw->pw_dir = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  len = strlen (first_unused);
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN (0, 6, result) >= room_left)
     goto no_more_room;
@@ -122,8 +135,9 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
 	   NISENTRYLEN (0, 6, result));
   first_unused[NISENTRYLEN (0, 6, result)] = '\0';
   pw->pw_shell = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  len = strlen (first_unused);
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   return 1;
 }
@@ -136,6 +150,7 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
   size_t room_left = buflen;
   char *line;
   int count;
+  size_t len;
 
   if (result == NULL)
     return 0;
@@ -158,9 +173,12 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
   strncpy (first_unused, NISENTRYVAL (entry, 0, result),
 	   NISENTRYLEN (entry, 0, result));
   first_unused[NISENTRYLEN (entry, 0, result)] = '\0';
+  len = strlen (first_unused);
+  if (len == 0) /* group table is corrupt */
+    return 0;
   gr->gr_name = first_unused;
-  room_left -= (strlen (first_unused) + 1);
-  first_unused += strlen (first_unused) + 1;
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN (entry, 1, result) >= room_left)
     goto no_more_room;
@@ -169,8 +187,9 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
 	   NISENTRYLEN (entry, 1, result));
   first_unused[NISENTRYLEN (entry, 1, result)] = '\0';
   gr->gr_passwd = first_unused;
-  room_left -= (strlen (first_unused) + 1);
-  first_unused += strlen (first_unused) + 1;
+  len = strlen (first_unused);
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN (entry, 2, result) >= room_left)
     goto no_more_room;
@@ -178,6 +197,9 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
   strncpy (first_unused, NISENTRYVAL (entry, 2, result),
 	   NISENTRYLEN (entry, 2, result));
   first_unused[NISENTRYLEN (entry, 2, result)] = '\0';
+  len = strlen (first_unused);
+  if (len == 0) /* We should always have an gid */
+    return 0;
   gr->gr_gid = atoi (first_unused);
   room_left -= (strlen (first_unused) + 1);
   first_unused += strlen (first_unused) + 1;
@@ -189,8 +211,9 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
 	   NISENTRYLEN (entry, 3, result));
   first_unused[NISENTRYLEN (entry, 3, result)] = '\0';
   line = first_unused;
-  room_left -= (strlen (line) + 1);
-  first_unused += strlen (line) + 1;
+  len = strlen (line);
+  room_left -= (len + 1);
+  first_unused += (len + 1);
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
   first_unused += __alignof__ (char *) - 1;
@@ -244,6 +267,7 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
 {
   char *first_unused = buffer;
   size_t room_left = buflen;
+  size_t len;
 
   if (result == NULL)
     return 0;
@@ -267,9 +291,12 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
   strncpy (first_unused, NISENTRYVAL (0, 0, result),
 	   NISENTRYLEN (0, 0, result));
   first_unused[NISENTRYLEN (0, 0, result)] = '\0';
+  len = strlen (first_unused);
+  if (len == 0)
+    return 0;
   sp->sp_namp = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   if (NISENTRYLEN (0, 1, result) >= room_left)
     goto no_more_room;
@@ -278,8 +305,9 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
 	   NISENTRYLEN (0, 1, result));
   first_unused[NISENTRYLEN (0, 1, result)] = '\0';
   sp->sp_pwdp = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  len = strlen (first_unused);
+  room_left -= (len + 1);
+  first_unused += (len + 1);
 
   sp->sp_lstchg = sp->sp_min = sp->sp_max = sp->sp_warn = sp->sp_inact =
     sp->sp_expire = sp->sp_flag = -1;