diff options
Diffstat (limited to 'nis/nss_nisplus/nisplus-parser.c')
-rw-r--r-- | nis/nss_nisplus/nisplus-parser.c | 78 |
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; |