From: Ulrich Drepper Date: Sun, 21 Dec 1997 21:17:55 +0000 (+0000) Subject: (internal_nis_getprotoent_r): Use strncpy instead of strcpy for X-Git-Tag: cvs/glibc-2_0_6pre5~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d806c1fb9fdc83d351eb2e988ffc3b0ab85aeb3;p=thirdparty%2Fglibc.git (internal_nis_getprotoent_r): Use strncpy instead of strcpy for security reasons. --- diff --git a/nis/nss_nis/nis-proto.c b/nis/nss_nis/nis-proto.c index 92ef1c00106..05437875b29 100644 --- a/nis/nss_nis/nis-proto.c +++ b/nis/nss_nis/nis-proto.c @@ -45,7 +45,7 @@ static struct response *start = NULL; static struct response *next = NULL; static int -saveit (int instatus, char *inkey, int inkeylen, char *inval, +saveit (int instatus, char *inkey, int inkeylen, char *inval, int invallen, char *indata) { if (instatus != YP_TRUE) @@ -68,7 +68,7 @@ saveit (int instatus, char *inkey, int inkeylen, char *inval, strncpy (next->val, inval, invallen); next->val[invallen] = '\0'; } - + return 0; } @@ -78,9 +78,9 @@ internal_nis_setprotoent (void) char *domainname; struct ypall_callback ypcb; enum nss_status status; - + yp_get_default_domain (&domainname); - + while (start != NULL) { if (start->val != NULL) @@ -90,12 +90,12 @@ internal_nis_setprotoent (void) free (next); } start = NULL; - + ypcb.foreach = saveit; ypcb.data = NULL; status = yperr2nss (yp_all (domainname, "protocols.bynumber", &ypcb)); next = start; - + return status; } @@ -128,9 +128,9 @@ _nss_nis_endprotoent (void) } start = NULL; next = NULL; - + __libc_lock_unlock (lock); - + return NSS_STATUS_SUCCESS; } @@ -148,12 +148,12 @@ internal_nis_getprotoent_r (struct protoent *proto, do { char *p; - + if (next == NULL) return NSS_STATUS_NOTFOUND; - p = strcpy (buffer, next->val); + p = strncpy (buffer, next->val, buflen); next = next->next; - + while (isspace (*p)) ++p; @@ -162,7 +162,7 @@ internal_nis_getprotoent_r (struct protoent *proto, return NSS_STATUS_TRYAGAIN; } while (!parse_res); - + return NSS_STATUS_SUCCESS; }