diff options
Diffstat (limited to 'usr/src/lib/libnsl/nss')
-rw-r--r-- | usr/src/lib/libnsl/nss/getauthattr.c | 17 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/getauuser.c | 17 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/getexecattr.c | 29 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/gethostby_door.c | 275 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/gethostbyname_r.c | 10 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/gethostent.c | 5 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/getipnodeby_door.c | 288 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/getprofattr.c | 16 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/getrpcent_r.c | 9 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/getuserattr.c | 17 | ||||
-rw-r--r-- | usr/src/lib/libnsl/nss/netdir_inet.c | 7 |
11 files changed, 77 insertions, 613 deletions
diff --git a/usr/src/lib/libnsl/nss/getauthattr.c b/usr/src/lib/libnsl/nss/getauthattr.c index d734e99ab9..b01c7447e8 100644 --- a/usr/src/lib/libnsl/nss/getauthattr.c +++ b/usr/src/lib/libnsl/nss/getauthattr.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -68,12 +67,12 @@ str2authattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) char *sep = KV_TOKEN_DELIMIT; authstr_t *auth = (authstr_t *)ent; - if ((instr >= buffer && (buffer + buflen) > instr) || - (buffer >= instr && (instr + lenstr) > buffer)) - return (NSS_STR_PARSE_PARSE); if (lenstr >= buflen) return (NSS_STR_PARSE_ERANGE); - (void) strncpy(buffer, instr, buflen); + + if (instr != buffer) + (void) strncpy(buffer, instr, buflen); + /* * Remove newline that nis (yp_match) puts at the * end of the entry it retrieves from the map. @@ -81,6 +80,10 @@ str2authattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) if (buffer[lenstr] == '\n') buffer[lenstr] = '\0'; + /* quick exit do not entry fill if not needed */ + if (ent == (void *)NULL) + return (NSS_STR_PARSE_SUCCESS); + auth->name = _strtok_escape(buffer, sep, &last); auth->res1 = _strtok_escape(NULL, sep, &last); auth->res2 = _strtok_escape(NULL, sep, &last); diff --git a/usr/src/lib/libnsl/nss/getauuser.c b/usr/src/lib/libnsl/nss/getauuser.c index 877a108ff8..f42b80cc5c 100644 --- a/usr/src/lib/libnsl/nss/getauuser.c +++ b/usr/src/lib/libnsl/nss/getauuser.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -72,12 +71,12 @@ str2auuser(const char *instr, int lenstr, void *ent, char *buffer, int buflen) char *sep = KV_TOKEN_DELIMIT; au_user_str_t *au_user = (au_user_str_t *)ent; - if ((instr >= buffer && (buffer + buflen) > instr) || - (buffer >= instr && (instr + lenstr) > buffer)) - return (NSS_STR_PARSE_PARSE); if (lenstr >= buflen) return (NSS_STR_PARSE_ERANGE); - (void) strncpy(buffer, instr, buflen); + + if (instr != buffer) + (void) strncpy(buffer, instr, buflen); + /* * Remove newline that nis (yp_match) puts at the * end of the entry it retrieves from the map. @@ -86,6 +85,10 @@ str2auuser(const char *instr, int lenstr, void *ent, char *buffer, int buflen) buffer[lenstr] = '\0'; } + /* quick exit do not entry fill if not needed */ + if (ent == (void *)NULL) + return (NSS_STR_PARSE_SUCCESS); + au_user->au_name = _strtok_escape(buffer, sep, &last); au_user->au_always = _strtok_escape(NULL, sep, &last); au_user->au_never = _strtok_escape(NULL, sep, &last); diff --git a/usr/src/lib/libnsl/nss/getexecattr.c b/usr/src/lib/libnsl/nss/getexecattr.c index 1990cea7ed..023667f092 100644 --- a/usr/src/lib/libnsl/nss/getexecattr.c +++ b/usr/src/lib/libnsl/nss/getexecattr.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -21,7 +20,7 @@ */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -99,15 +98,12 @@ str2execattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) char *sep = KV_TOKEN_DELIMIT; execstr_t *exec = (execstr_t *)ent; - if (exec == NULL) - return (NSS_STR_PARSE_PARSE); - - if ((instr >= buffer && (buffer + buflen) > instr) || - (buffer >= instr && (instr + lenstr) > buffer)) - return (NSS_STR_PARSE_PARSE); if (lenstr >= buflen) return (NSS_STR_PARSE_ERANGE); - (void) strncpy(buffer, instr, buflen); + + if (instr != buffer) + (void) strncpy(buffer, instr, buflen); + /* * Remove newline that nis (yp_match) puts at the * end of the entry it retrieves from the map. @@ -116,6 +112,10 @@ str2execattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) buffer[lenstr] = '\0'; } + /* quick exit do not entry fill if not needed */ + if (ent == (void *)NULL) + return (NSS_STR_PARSE_SUCCESS); + exec->name = _strtok_escape(buffer, sep, &last); exec->policy = _strtok_escape(NULL, sep, &last); exec->type = _strtok_escape(NULL, sep, &last); @@ -245,9 +245,12 @@ retry_policy: res = nss_search(&pexec_root, _nsw_initf_execattr, getby_flag, &arg); - _nss_db_state_destr(pexec_root.s); + if (pexec_root.s != NULL) + _nss_db_state_destr( + pexec_root.s); } - _nss_db_state_destr(prof_root.s); + if (prof_root.s != NULL) + _nss_db_state_destr(prof_root.s); (void) mutex_unlock(&_nsw_exec_lock); if ((pres == NSS_SUCCESS) || (conf == NULL)) break; diff --git a/usr/src/lib/libnsl/nss/gethostby_door.c b/usr/src/lib/libnsl/nss/gethostby_door.c index 8b7f66f46f..4c3bdebc38 100644 --- a/usr/src/lib/libnsl/nss/gethostby_door.c +++ b/usr/src/lib/libnsl/nss/gethostby_door.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,7 +18,6 @@ * * CDDL HEADER END */ - /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -40,285 +38,20 @@ #ifdef PIC -static struct hostent *process_gethost(struct hostent *, char *, int, int *, - nsc_data_t *); - struct hostent * _door_gethostbyname_r(const char *name, struct hostent *result, char *buffer, int buflen, int *h_errnop) { - - /* - * allocate space on the stack for the nscd to return - * host and host alias information - */ - union { - nsc_data_t s_d; - char s_b[8192]; - } space; - nsc_data_t *sptr; - int ndata; - int adata; - struct hostent *resptr = NULL; - - if ((name == NULL) || - (strlen(name) >= (sizeof (space) - sizeof (nsc_data_t)))) { - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - adata = (sizeof (nsc_call_t) + strlen(name) + 1); - ndata = sizeof (space); - space.s_d.nsc_call.nsc_callnumber = GETHOSTBYNAME; - (void) strcpy(space.s_d.nsc_call.nsc_u.name, name); - sptr = &space.s_d; - - switch (_nsc_trydoorcall(&sptr, &ndata, &adata)) { - case SUCCESS: /* positive cache hit */ - break; - case NOTFOUND: /* negative cache hit */ - if (h_errnop) - *h_errnop = space.s_d.nsc_ret.nsc_errno; - return (NULL); - default: - return ((struct hostent *)_switch_gethostbyname_r(name, + return ((struct hostent *)_switch_gethostbyname_r(name, result, buffer, buflen, h_errnop)); - } - resptr = process_gethost(result, buffer, buflen, h_errnop, sptr); - - /* - * check if doors realloced buffer underneath of us.... - * munmap or suffer a memory leak - */ - - if (sptr != &space.s_d) { - munmap((char *)sptr, ndata); /* return memory */ - } - - return (resptr); } struct hostent * _door_gethostbyaddr_r(const char *addr, int length, int type, struct hostent *result, char *buffer, int buflen, int *h_errnop) { - /* - * allocate space on the stack for the nscd to return - * host and host alias information - */ - union { - nsc_data_t s_d; - char s_b[8192]; - } space; - nsc_data_t *sptr; - int ndata; - int adata; - struct hostent *resptr = NULL; - - if (addr == NULL) { - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - ndata = sizeof (space); - adata = length + sizeof (nsc_call_t) + 1; - sptr = &space.s_d; - - space.s_d.nsc_call.nsc_callnumber = GETHOSTBYADDR; - space.s_d.nsc_call.nsc_u.addr.a_type = type; - space.s_d.nsc_call.nsc_u.addr.a_length = length; - (void) memcpy(space.s_d.nsc_call.nsc_u.addr.a_data, addr, length); - - switch (_nsc_trydoorcall(&sptr, &ndata, &adata)) { - case SUCCESS: /* positive cache hit */ - break; - case NOTFOUND: /* negative cache hit */ - if (h_errnop) - *h_errnop = space.s_d.nsc_ret.nsc_errno; - return (NULL); - default: - return ((struct hostent *)_switch_gethostbyaddr_r(addr, + return ((struct hostent *)_switch_gethostbyaddr_r(addr, length, type, result, buffer, buflen, h_errnop)); - } - - resptr = process_gethost(result, buffer, buflen, h_errnop, sptr); - - /* - * check if doors realloced buffer underneath of us.... - * munmap it or suffer a memory leak - */ - - if (sptr != &space.s_d) { - munmap((char *)sptr, ndata); /* return memory */ - } - - return (resptr); - -} - -#if !defined(_LP64) - -static struct hostent * -process_gethost(struct hostent *result, char *buffer, int buflen, - int *h_errnop, nsc_data_t *sptr) -{ - int i; - - char *fixed; - - fixed = (char *)(((int)buffer +3) & ~3); - buflen -= fixed - buffer; - buffer = fixed; - - if (buflen + sizeof (struct hostent) - < sptr->nsc_ret.nsc_bufferbytesused) { - /* - * no enough space allocated by user - */ - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - (void) memcpy(buffer, - sptr->nsc_ret.nsc_u.buff + sizeof (struct hostent), - sptr->nsc_ret.nsc_bufferbytesused - sizeof (struct hostent)); - - sptr->nsc_ret.nsc_u.hst.h_name += (int)buffer; - sptr->nsc_ret.nsc_u.hst.h_aliases = - (char **)((char *)sptr->nsc_ret.nsc_u.hst.h_aliases + (int)buffer); - sptr->nsc_ret.nsc_u.hst.h_addr_list = - (char **)((char *)sptr->nsc_ret.nsc_u.hst.h_addr_list + - (int)buffer); - for (i = 0; sptr->nsc_ret.nsc_u.hst.h_aliases[i]; i++) { - sptr->nsc_ret.nsc_u.hst.h_aliases[i] += (int)buffer; - } - for (i = 0; sptr->nsc_ret.nsc_u.hst.h_addr_list[i]; i++) { - sptr->nsc_ret.nsc_u.hst.h_addr_list[i] += (int)buffer; - } - - *result = sptr->nsc_ret.nsc_u.hst; - - return (result); } -#else /* _LP64 */ - -#define RNDUP(buf, n) (((uintptr_t)buf + n - 1l) & ~(n - 1l)) - -static struct hostent * -process_gethost(struct hostent *result, char *buffer, int buflen, - int *h_errnop, nsc_data_t *sptr) -{ - char *fixed; - char *dest; - char *start; - char **aliaseslist; - char **addrlist; - int *alias; - int *address; - size_t strs; - int numaliases; - int numaddrs; - int i; - - fixed = (char *)RNDUP(buffer, sizeof (char *)); - buflen -= fixed - buffer; - buffer = fixed; - - if (buflen < 0) { - /* no enough space allocated by user */ - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - /* find out whether the user has provided sufficient space */ - - start = sptr->nsc_ret.nsc_u.buff + sizeof (struct hostent32); - strs = 1 + strlen(sptr->nsc_ret.nsc_u.hst.h_name + start); - alias = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_aliases); - for (numaliases = 0; alias[numaliases]; numaliases++) - strs += 1 + strlen(start + alias[numaliases]); - strs = RNDUP(strs, sizeof (int)); - strs += sizeof (char *) * (numaliases + 1); - address = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_addr_list); - for (numaddrs = 0; address[numaddrs]; numaddrs++) - strs += RNDUP(sptr->nsc_ret.nsc_u.hst.h_length, sizeof (int)); - strs += sizeof (char *) * (numaddrs + 1); - - if (buflen < strs) { - - /* no enough space allocated by user */ - - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - - /* - * allocat the h_aliases list and the h_addr_list first to align 'em. - */ - - dest = buffer; - aliaseslist = (char **)dest; - dest += sizeof (char *) * (numaliases + 1); - addrlist = (char **)dest; - dest += sizeof (char *) * (numaddrs + 1); - - /* fill out h_name */ - - start = sptr->nsc_ret.nsc_u.buff + sizeof (struct hostent32); - (void) strcpy(dest, sptr->nsc_ret.nsc_u.hst.h_name + start); - strs = 1 + strlen(sptr->nsc_ret.nsc_u.hst.h_name + start); - result->h_name = dest; - dest += strs; - - /* - * fill out the h_aliases list - */ - for (i = 0; i < numaliases; i++) { - alias = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_aliases); - (void) strcpy(dest, start + alias[i]); - strs = 1 + strlen(start + alias[i]); - aliaseslist[i] = dest; - dest += strs; - } - aliaseslist[i] = 0; /* null term ptr chain */ - - result->h_aliases = aliaseslist; - - /* - * fill out the h_addr list - */ - - dest = (char *)RNDUP(dest, sizeof (int)); - - for (i = 0; i < numaddrs; i++) { - address = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_addr_list); - (void) memcpy(dest, start + address[i], - sptr->nsc_ret.nsc_u.hst.h_length); - strs = sptr->nsc_ret.nsc_u.hst.h_length; - addrlist[i] = dest; - dest += strs; - dest = (char *)RNDUP(dest, sizeof (int)); - } - - addrlist[i] = 0; /* null term ptr chain */ - - result->h_addr_list = addrlist; - - result->h_length = sptr->nsc_ret.nsc_u.hst.h_length; - result->h_addrtype = sptr->nsc_ret.nsc_u.hst.h_addrtype; - - return (result); -} -#endif /* _LP64 */ #endif /* PIC */ diff --git a/usr/src/lib/libnsl/nss/gethostbyname_r.c b/usr/src/lib/libnsl/nss/gethostbyname_r.c index 27435b95fe..7a3c5aaaa0 100644 --- a/usr/src/lib/libnsl/nss/gethostbyname_r.c +++ b/usr/src/lib/libnsl/nss/gethostbyname_r.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -151,7 +150,10 @@ gethostbyaddr_r(const char *addr, int length, int type, struct netconfig *nconf; struct nss_netdirbyaddr_in nssin; union nss_netdirbyaddr_out nssout; - int neterr; + int neterr, dummy; + + if (h_errnop == NULL) + h_errnop = &dummy; if (type != AF_INET) { *h_errnop = HOST_NOT_FOUND; diff --git a/usr/src/lib/libnsl/nss/gethostent.c b/usr/src/lib/libnsl/nss/gethostent.c index 8cbc3b9dec..c02c8c5ebf 100644 --- a/usr/src/lib/libnsl/nss/gethostent.c +++ b/usr/src/lib/libnsl/nss/gethostent.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. diff --git a/usr/src/lib/libnsl/nss/getipnodeby_door.c b/usr/src/lib/libnsl/nss/getipnodeby_door.c index 8c0423196e..17e1f953c1 100644 --- a/usr/src/lib/libnsl/nss/getipnodeby_door.c +++ b/usr/src/lib/libnsl/nss/getipnodeby_door.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -19,7 +18,6 @@ * * CDDL HEADER END */ - /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -41,298 +39,20 @@ #ifdef PIC -static struct hostent *__process_getipnode(struct hostent *, char *, int, int *, - nsc_data_t *); - struct hostent * _door_getipnodebyname_r(const char *name, struct hostent *result, char *buffer, int buflen, int af_family, int flags, int *h_errnop) { - - /* - * allocate space on the stack for the nscd to return - * host and host alias information - */ - union { - nsc_data_t s_d; - char s_b[8192]; - } space; - nsc_data_t *sptr; - int ndata; - int adata; - struct hostent *resptr = NULL; - - if ((name == NULL) || - (strlen(name) >= (sizeof (space) - sizeof (nsc_data_t) - - 2 * sizeof (int)))) { - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - adata = (sizeof (nsc_call_t) + strlen(name) + 1 + 2 * sizeof (int)); - ndata = sizeof (space); - space.s_d.nsc_call.nsc_callnumber = GETIPNODEBYNAME; - space.s_d.nsc_call.nsc_u.ipnode.af_family = af_family; - space.s_d.nsc_call.nsc_u.ipnode.flags = flags; - (void) strcpy(space.s_d.nsc_call.nsc_u.ipnode.name, name); - sptr = &space.s_d; - - switch (_nsc_trydoorcall(&sptr, &ndata, &adata)) { - case SUCCESS: /* positive cache hit */ - break; - case NOTFOUND: /* negative cache hit */ - if (h_errnop) - *h_errnop = space.s_d.nsc_ret.nsc_errno; - return (NULL); - default: - return ((struct hostent *)_switch_getipnodebyname_r(name, + return ((struct hostent *)_switch_getipnodebyname_r(name, result, buffer, buflen, af_family, flags, h_errnop)); - } - resptr = __process_getipnode(result, buffer, buflen, h_errnop, sptr); - - /* - * check if doors realloced buffer underneath of us.... - * munmap or suffer a memory leak - */ - - if (sptr != &space.s_d) { - munmap((char *)sptr, ndata); /* return memory */ - } - - return (resptr); } struct hostent * _door_getipnodebyaddr_r(const char *addr, int length, int type, struct hostent *result, char *buffer, int buflen, int *h_errnop) { - /* - * allocate space on the stack for the nscd to return - * host and host alias information - */ - union { - nsc_data_t s_d; - char s_b[8192]; - } space; - nsc_data_t *sptr; - int ndata; - int adata; - struct hostent *resptr = NULL; - - if (addr == NULL) { - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - ndata = sizeof (space); - adata = length + sizeof (nsc_call_t) + 1; - sptr = &space.s_d; - - space.s_d.nsc_call.nsc_callnumber = GETIPNODEBYADDR; - space.s_d.nsc_call.nsc_u.addr.a_type = type; - space.s_d.nsc_call.nsc_u.addr.a_length = length; - (void) memcpy(space.s_d.nsc_call.nsc_u.addr.a_data, addr, length); - - switch (_nsc_trydoorcall(&sptr, &ndata, &adata)) { - case SUCCESS: /* positive cache hit */ - break; - case NOTFOUND: /* negative cache hit */ - if (h_errnop) - *h_errnop = space.s_d.nsc_ret.nsc_errno; - return (NULL); - default: - return ((struct hostent *)_switch_getipnodebyaddr_r(addr, + return ((struct hostent *)_switch_getipnodebyaddr_r(addr, length, type, result, buffer, buflen, h_errnop)); - } - - resptr = __process_getipnode(result, buffer, buflen, h_errnop, sptr); - - /* - * check if doors realloced buffer underneath of us.... - * munmap it or suffer a memory leak - */ - - if (sptr != &space.s_d) { - munmap((char *)sptr, ndata); /* return memory */ - } - - return (resptr); -} - -#if !defined(_LP64) - -static struct hostent * -__process_getipnode(struct hostent *result, char *buffer, int buflen, - int *h_errnop, nsc_data_t *sptr) -{ - int i; - - char *fixed; - - fixed = (char *)ROUND_UP((int)buffer, sizeof (char *)); - buflen -= fixed - buffer; - buffer = fixed; - - if (buflen + sizeof (struct hostent) - < sptr->nsc_ret.nsc_bufferbytesused) { - /* - * no enough space allocated by user - */ - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - (void) memcpy(buffer, - sptr->nsc_ret.nsc_u.buff + sizeof (struct hostent), - sptr->nsc_ret.nsc_bufferbytesused - sizeof (struct hostent)); - - sptr->nsc_ret.nsc_u.hst.h_name += (int)buffer; - sptr->nsc_ret.nsc_u.hst.h_aliases = - (char **)((char *)sptr->nsc_ret.nsc_u.hst.h_aliases + (int)buffer); - sptr->nsc_ret.nsc_u.hst.h_addr_list = - (char **)((char *)sptr->nsc_ret.nsc_u.hst.h_addr_list + - (int)buffer); - for (i = 0; sptr->nsc_ret.nsc_u.hst.h_aliases[i]; i++) { - sptr->nsc_ret.nsc_u.hst.h_aliases[i] += (int)buffer; - } - for (i = 0; sptr->nsc_ret.nsc_u.hst.h_addr_list[i]; i++) { - sptr->nsc_ret.nsc_u.hst.h_addr_list[i] += (int)buffer; - } - - *result = sptr->nsc_ret.nsc_u.hst; - - return (result); -} - -#else /* _LP64 */ - -static struct hostent * -__process_getipnode(struct hostent *result, char *buffer, int buflen, - int *h_errnop, nsc_data_t *sptr) -{ - char *fixed; - char *dest; - char *start; - char **aliaseslist; - char **addrlist; - int *alias; - int *address; - size_t strs; - int numaliases; - int numaddrs; - int i; - - fixed = (char *)ROUND_UP(buffer, sizeof (char *)); - buflen -= fixed - buffer; - buffer = fixed; - if (buflen < 0) { - /* no enough space allocated by user */ - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - /* - * find out whether the user has provided sufficient space - */ - start = sptr->nsc_ret.nsc_u.buff + sizeof (struct hostent32); - /* - * Length of hostname + null - */ - strs = 1 + strlen(sptr->nsc_ret.nsc_u.hst.h_name + start); - /* - * length of all aliases + null - */ - alias = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_aliases); - for (numaliases = 0; alias[numaliases]; numaliases++) - strs += 1 + strlen(start + alias[numaliases]); - /* - * Realign on word boundary - */ - strs = ROUND_UP(strs, sizeof (char *)); - /* - * Count the array of pointers to all aliases + null pointer - */ - strs += sizeof (char *) * (numaliases + 1); - /* - * length of all addresses + null. Also, account for word alignment. - */ - address = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_addr_list); - for (numaddrs = 0; address[numaddrs]; numaddrs++) { - strs += sptr->nsc_ret.nsc_u.hst.h_length; - strs = ROUND_UP(strs, sizeof (char *)); - } - /* - * Count the array of pointers to all addresses + null pointer - */ - strs += sizeof (char *) * (numaddrs + 1); - - if (buflen < strs) { - - /* no enough space allocated by user */ - - errno = ERANGE; - if (h_errnop) - *h_errnop = HOST_NOT_FOUND; - return (NULL); - } - - /* - * allocat the h_aliases list and the h_addr_list first to align 'em. - */ - dest = buffer; - aliaseslist = (char **)dest; - dest += sizeof (char *) * (numaliases + 1); - addrlist = (char **)dest; - dest += sizeof (char *) * (numaddrs + 1); - /* - * fill out h_name - */ - start = sptr->nsc_ret.nsc_u.buff + sizeof (struct hostent32); - (void) strcpy(dest, sptr->nsc_ret.nsc_u.hst.h_name + start); - strs = 1 + strlen(sptr->nsc_ret.nsc_u.hst.h_name + start); - result->h_name = dest; - dest += strs; - /* - * fill out the h_aliases list - */ - alias = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_aliases); - for (i = 0; i < numaliases; i++) { - (void) strcpy(dest, start + alias[i]); - aliaseslist[i] = dest; - dest += 1 + strlen(start + alias[i]); - } - aliaseslist[i] = 0; /* null term ptr chain */ - result->h_aliases = aliaseslist; - - /* - * fill out the h_addr list - */ - dest = (char *)ROUND_UP(dest, sizeof (char *)); - address = (int *)(start + sptr->nsc_ret.nsc_u.hst.h_addr_list); - for (i = 0; i < numaddrs; i++) { - (void) memcpy(dest, start + address[i], - sptr->nsc_ret.nsc_u.hst.h_length); - addrlist[i] = dest; - dest += sptr->nsc_ret.nsc_u.hst.h_length; - dest = (char *)ROUND_UP(dest, sizeof (char *)); - } - - addrlist[i] = 0; /* null term ptr chain */ - - result->h_addr_list = addrlist; - - result->h_length = sptr->nsc_ret.nsc_u.hst.h_length; - result->h_addrtype = sptr->nsc_ret.nsc_u.hst.h_addrtype; - - return (result); } -#endif /* _LP64 */ #endif /* PIC */ diff --git a/usr/src/lib/libnsl/nss/getprofattr.c b/usr/src/lib/libnsl/nss/getprofattr.c index ffda122e05..bf5f7e94fa 100644 --- a/usr/src/lib/libnsl/nss/getprofattr.c +++ b/usr/src/lib/libnsl/nss/getprofattr.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -67,12 +66,11 @@ str2profattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) char *sep = KV_TOKEN_DELIMIT; profstr_t *prof = (profstr_t *)ent; - if ((instr >= buffer && (buffer + buflen) > instr) || - (buffer >= instr && (instr + lenstr) > buffer)) - return (NSS_STR_PARSE_PARSE); if (lenstr >= buflen) return (NSS_STR_PARSE_ERANGE); - (void) strncpy(buffer, instr, buflen); + if (instr != buffer) + (void) strncpy(buffer, instr, buflen); + /* * Remove newline that nis (yp_match) puts at the * end of the entry it retrieves from the map. @@ -80,6 +78,10 @@ str2profattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) if (buffer[lenstr] == '\n') buffer[lenstr] = '\0'; + /* quick exit do not entry fill if not needed */ + if (ent == (void *)NULL) + return (NSS_STR_PARSE_SUCCESS); + prof->name = _strtok_escape(buffer, sep, &last); prof->res1 = _strtok_escape(NULL, sep, &last); prof->res2 = _strtok_escape(NULL, sep, &last); diff --git a/usr/src/lib/libnsl/nss/getrpcent_r.c b/usr/src/lib/libnsl/nss/getrpcent_r.c index 206b3896d0..e794ee7538 100644 --- a/usr/src/lib/libnsl/nss/getrpcent_r.c +++ b/usr/src/lib/libnsl/nss/getrpcent_r.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -59,6 +58,10 @@ getrpcbyname_r(const char *name, struct rpcent *result, char *buffer, nss_XbyY_args_t arg; nss_status_t res; + if (name == (const char *)NULL) { + errno = ERANGE; + return (NULL); + } NSS_XbyY_INIT(&arg, result, buffer, buflen, str2rpcent); arg.key.name = name; arg.stayopen = rpc_stayopen; diff --git a/usr/src/lib/libnsl/nss/getuserattr.c b/usr/src/lib/libnsl/nss/getuserattr.c index 30b196c8de..5106155854 100644 --- a/usr/src/lib/libnsl/nss/getuserattr.c +++ b/usr/src/lib/libnsl/nss/getuserattr.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -75,12 +74,12 @@ str2userattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) char *sep = KV_TOKEN_DELIMIT; userstr_t *user = (userstr_t *)ent; - if ((instr >= buffer && (buffer + buflen) > instr) || - (buffer >= instr && (instr + lenstr) > buffer)) - return (NSS_STR_PARSE_PARSE); if (lenstr >= buflen) return (NSS_STR_PARSE_ERANGE); - (void) strncpy(buffer, instr, buflen); + + if (instr != buffer) + (void) strncpy(buffer, instr, buflen); + /* * Remove newline that nis (yp_match) puts at the * end of the entry it retrieves from the map. @@ -89,6 +88,10 @@ str2userattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen) buffer[lenstr] = '\0'; } + /* quick exit do not entry fill if not needed */ + if (ent == (void *)NULL) + return (NSS_STR_PARSE_SUCCESS); + user->name = _strtok_escape(buffer, sep, &last); user->qualifier = _strtok_escape(NULL, sep, &last); user->res1 = _strtok_escape(NULL, sep, &last); diff --git a/usr/src/lib/libnsl/nss/netdir_inet.c b/usr/src/lib/libnsl/nss/netdir_inet.c index a8fc687daf..411f24c63c 100644 --- a/usr/src/lib/libnsl/nss/netdir_inet.c +++ b/usr/src/lib/libnsl/nss/netdir_inet.c @@ -90,17 +90,10 @@ #define UDPDEV "/dev/udp" #define UDP6DEV "/dev/udp6" -#ifdef PIC -#define DOOR_GETHOSTBYNAME_R _door_gethostbyname_r -#define DOOR_GETHOSTBYADDR_R _door_gethostbyaddr_r -#define DOOR_GETIPNODEBYNAME_R _door_getipnodebyname_r -#define DOOR_GETIPNODEBYADDR_R _door_getipnodebyaddr_r -#else #define DOOR_GETHOSTBYNAME_R _switch_gethostbyname_r #define DOOR_GETHOSTBYADDR_R _switch_gethostbyaddr_r #define DOOR_GETIPNODEBYNAME_R _switch_getipnodebyname_r #define DOOR_GETIPNODEBYADDR_R _switch_getipnodebyaddr_r -#endif /* PIC */ #define DONT_SORT "SORT_ADDRS=NO" #define DONT_SORT2 "SORT_ADDRS=FALSE" |