From fb776f3ef3b2b7eaf7e92305b8b2dc480f31f3ff Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sun, 10 Nov 2002 11:06:36 +0000 Subject: * nss/getXXent.c (GETFUNC_NAME): Use union type to avoid strict aliasing problem. * nss/getXXbyYY_r.c (INTERNAL): Likewise. * nss/getnssent_r.c (__nss_getent_r): Likewise. (__nss_setent): Likewise. (__nss_getent_r): Likewise. * inet/getnetgrent_r.c (innetgr): Likewise. (__internal_setnetgrent_reuse): Likewise. (internal_getnetgrent_r): Likewise. * inet/ether_hton.c (ether_hostton): Likewise. * inet/ether_ntoh.c (ether_ntohost): Likewise. * sunrpc/netname.c (netname2user): Likewise. * sunrpc/publickey.c (getpublickey): Likewise. (getsecretkey): Likewise. --- inet/ether_hton.c | 16 ++++++++----- inet/ether_ntoh.c | 16 ++++++++----- inet/getnetgrent_r.c | 68 +++++++++++++++++++++++++++++++++++----------------- nss/getXXbyYY_r.c | 45 ++++++++++++++++++---------------- nss/getXXent.c | 8 +++++-- nss/getnssent_r.c | 52 ++++++++++++++++++++++++++-------------- sunrpc/netname.c | 16 ++++++++----- sunrpc/publickey.c | 32 +++++++++++++++---------- 8 files changed, 161 insertions(+), 92 deletions(-) diff --git a/inet/ether_hton.c b/inet/ether_hton.c index 70dc2fe071..64f5ab5d36 100644 --- a/inet/ether_hton.c +++ b/inet/ether_hton.c @@ -39,25 +39,29 @@ ether_hostton (const char *hostname, struct ether_addr *addr) static service_user *startp; static lookup_function start_fct; service_user *nip; - lookup_function fct; + union + { + lookup_function f; + void *ptr; + } fct; int no_more; enum nss_status status = NSS_STATUS_UNAVAIL; struct etherent etherent; if (startp == NULL) { - no_more = __nss_ethers_lookup (&nip, "gethostton_r", (void **) &fct); + no_more = __nss_ethers_lookup (&nip, "gethostton_r", &fct.ptr); if (no_more) startp = (service_user *) -1; else { startp = nip; - start_fct = fct; + start_fct = fct.f; } } else { - fct = start_fct; + fct.f = start_fct; no_more = (nip = startp) == (service_user *) -1; } @@ -65,9 +69,9 @@ ether_hostton (const char *hostname, struct ether_addr *addr) { char buffer[1024]; - status = (*fct) (hostname, ðerent, buffer, sizeof buffer, &errno); + status = (*fct.f) (hostname, ðerent, buffer, sizeof buffer, &errno); - no_more = __nss_next (&nip, "gethostton_r", (void **) &fct, status, 0); + no_more = __nss_next (&nip, "gethostton_r", &fct.ptr, status, 0); } if (status == NSS_STATUS_SUCCESS) diff --git a/inet/ether_ntoh.c b/inet/ether_ntoh.c index ecddc9d8ac..ad4165cb3e 100644 --- a/inet/ether_ntoh.c +++ b/inet/ether_ntoh.c @@ -40,25 +40,29 @@ ether_ntohost (char *hostname, const struct ether_addr *addr) static service_user *startp; static lookup_function start_fct; service_user *nip; - lookup_function fct; + union + { + lookup_function f; + void *ptr; + } fct; int no_more; enum nss_status status = NSS_STATUS_UNAVAIL; struct etherent etherent; if (startp == NULL) { - no_more = __nss_ethers_lookup (&nip, "getntohost_r", (void **) &fct); + no_more = __nss_ethers_lookup (&nip, "getntohost_r", &fct.ptr); if (no_more) startp = (service_user *) -1; else { startp = nip; - start_fct = fct; + start_fct = fct.f; } } else { - fct = start_fct; + fct.f = start_fct; no_more = (nip = startp) == (service_user *) -1; } @@ -66,9 +70,9 @@ ether_ntohost (char *hostname, const struct ether_addr *addr) { char buffer[1024]; - status = (*fct) (addr, ðerent, buffer, sizeof buffer, &errno); + status = (*fct.f) (addr, ðerent, buffer, sizeof buffer, &errno); - no_more = __nss_next (&nip, "getntohost_r", (void **) &fct, status, 0); + no_more = __nss_next (&nip, "getntohost_r", &fct.ptr, status, 0); } if (status == NSS_STATUS_SUCCESS) diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c index a0fb6f42a1..dee90ad389 100644 --- a/inet/getnetgrent_r.c +++ b/inet/getnetgrent_r.c @@ -96,19 +96,23 @@ internal_function __internal_setnetgrent_reuse (const char *group, struct __netgrent *datap, int *errnop) { - enum nss_status (*fct) (const char *, struct __netgrent *); + union + { + enum nss_status (*f) (const char *, struct __netgrent *); + void *ptr; + } fct; enum nss_status status = NSS_STATUS_UNAVAIL; struct name_list *new_elem; int no_more; /* Cycle through all the services and run their setnetgrent functions. */ - no_more = setup ((void **) &fct, "setnetgrent", 1); + no_more = setup (&fct.ptr, "setnetgrent", 1); while (! no_more) { /* Ignore status, we force check in `__nss_next'. */ - status = (*fct) (group, datap); + status = (*fct.f) (group, datap); - no_more = __nss_next (&nip, "setnetgrent", (void **) &fct, status, 0); + no_more = __nss_next (&nip, "setnetgrent", &fct.ptr, status, 0); } /* Add the current group to the list of known groups. */ @@ -158,21 +162,25 @@ static void internal_endnetgrent (struct __netgrent *datap) { service_user *old_nip; - enum nss_status (*fct) (struct __netgrent *); + union + { + enum nss_status (*f) (struct __netgrent *); + void *ptr; + } fct; int no_more; /* Remember which was the last used service. */ old_nip = nip; /* Cycle through all the services and run their endnetgrent functions. */ - no_more = setup ((void **) &fct, "endnetgrent", 1); + no_more = setup (&fct.ptr, "endnetgrent", 1); while (! no_more) { /* Ignore status, we force check in `__nss_next'. */ - (void) (*fct) (datap); + (void) (*fct.f) (datap); no_more = (nip == old_nip - || __nss_next (&nip, "endnetgrent", (void **) &fct, 0, 1)); + || __nss_next (&nip, "endnetgrent", &fct.ptr, 0, 1)); } /* Now free list of all netgroup names from last run. */ @@ -197,7 +205,11 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp, struct __netgrent *datap, char *buffer, size_t buflen, int *errnop) { - enum nss_status (*fct) (struct __netgrent *, char *, size_t, int *); + union + { + enum nss_status (*f) (struct __netgrent *, char *, size_t, int *); + void *ptr; + } fct; int no_more; /* Initialize status to return if no more functions are found. */ @@ -206,10 +218,10 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp, /* Run through available functions, starting with the same function last run. We will repeat each function as long as it succeeds, and then go on to the next service action. */ - no_more = setup ((void **) &fct, "getnetgrent_r", 0); + no_more = setup (&fct.ptr, "getnetgrent_r", 0); while (! no_more) { - status = (*fct) (datap, buffer, buflen, &errno); + status = (*fct.f) (datap, buffer, buflen, &errno); if (status == NSS_STATUS_RETURN) { @@ -262,7 +274,7 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp, } } - no_more = __nss_next (&nip, "getnetgrent_r", (void **) &fct, status, 0); + no_more = __nss_next (&nip, "getnetgrent_r", &fct.ptr, status, 0); } if (status == NSS_STATUS_SUCCESS) @@ -299,9 +311,21 @@ int innetgr (const char *netgroup, const char *host, const char *user, const char *domain) { - int (*setfct) (const char *, struct __netgrent *); - void (*endfct) (struct __netgrent *); - int (*getfct) (struct __netgrent *, char *, size_t, int *); + union + { + int (*f) (const char *, struct __netgrent *); + void *ptr; + } setfct; + union + { + void (*f) (struct __netgrent *); + void *ptr; + } endfct; + union + { + int (*f) (struct __netgrent *, char *, size_t, int *); + void *ptr; + } getfct; struct name_list *known = NULL; struct name_list *needed = NULL; int result = 0; @@ -315,7 +339,7 @@ innetgr (const char *netgroup, const char *host, const char *user, the work during one walk through the service list. */ while (1) { - no_more = setup ((void **) &setfct, "setnetgrent", 1); + no_more = setup (&setfct.ptr, "setnetgrent", 1); while (! no_more) { enum nss_status status; @@ -325,13 +349,13 @@ innetgr (const char *netgroup, const char *host, const char *user, __bzero (&entry, sizeof (entry)); /* Open netgroup. */ - status = (*setfct) (current_group, &entry); + status = (*setfct.f) (current_group, &entry); if (status == NSS_STATUS_SUCCESS - && __nss_lookup (&nip, "getnetgrent_r", (void **) &getfct) == 0) + && __nss_lookup (&nip, "getnetgrent_r", &getfct.ptr) == 0) { char buffer[1024]; - while ((*getfct) (&entry, buffer, sizeof buffer, &errno) + while ((*getfct.f) (&entry, buffer, sizeof buffer, &errno) == NSS_STATUS_SUCCESS) { if (entry.type == group_val) @@ -389,12 +413,12 @@ innetgr (const char *netgroup, const char *host, const char *user, } /* Free all resources of the service. */ - if (__nss_lookup (&nip, "endnetgrent", (void **) &endfct) == 0) - (*endfct) (&entry); + if (__nss_lookup (&nip, "endnetgrent", &endfct.ptr) == 0) + (*endfct.f) (&entry); /* Look for the next service. */ no_more = __nss_next (&nip, "setnetgrent", - (void **) &setfct, status, 0); + &setfct.ptr, status, 0); } if (result == 0 && needed != NULL) diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c index ca81cf4c8f..5bb28f7141 100644 --- a/nss/getXXbyYY_r.c +++ b/nss/getXXbyYY_r.c @@ -32,30 +32,30 @@ #endif /*******************************************************************\ |* Here we assume several symbols to be defined: *| -|* *| +|* *| |* LOOKUP_TYPE - the return type of the function *| -|* *| +|* *| |* FUNCTION_NAME - name of the non-reentrant function *| -|* *| +|* *| |* DATABASE_NAME - name of the database the function accesses *| |* (e.g., host, services, ...) *| -|* *| +|* *| |* ADD_PARAMS - additional parameter, can vary in number *| -|* *| +|* *| |* ADD_VARIABLES - names of additional parameter *| -|* *| +|* *| |* Optionally the following vars can be defined: *| -|* *| +|* *| |* NEED_H_ERRNO - an extra parameter will be passed to point to *| |* the global `h_errno' variable. *| -|* *| +|* *| |* NEED__RES - the global _res variable might be used so we *| -|* will have to initialize it if necessary *| -|* *| +|* will have to initialize it if necessary *| +|* *| |* PREPROCESS - code run before anything else *| -|* *| +|* *| |* POSTPROCESS - code run after the lookup *| -|* *| +|* *| \*******************************************************************/ /* To make the real sources a bit prettier. */ @@ -130,7 +130,12 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, static service_user *startp; static lookup_function start_fct; service_user *nip; - lookup_function fct; + union + { + lookup_function l; + void *ptr; + } fct; + int no_more; enum nss_status status = NSS_STATUS_UNAVAIL; #ifdef USE_NSCD @@ -175,13 +180,13 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, if (startp == NULL) { - no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, (void **) &fct); + no_more = DB_LOOKUP_FCT (&nip, REENTRANT_NAME_STRING, &fct.ptr); if (no_more) startp = (service_user *) -1l; else { startp = nip; - start_fct = fct; + start_fct = fct.l; #ifdef NEED__RES /* The resolver code will really be used so we have to @@ -201,7 +206,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, } else { - fct = start_fct; + fct.l = start_fct; no_more = (nip = startp) == (service_user *) -1l; } @@ -211,8 +216,8 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, any_service = true; #endif - status = DL_CALL_FCT (fct, (ADD_VARIABLES, resbuf, buffer, buflen, - &errno H_ERRNO_VAR)); + status = DL_CALL_FCT (fct.l, (ADD_VARIABLES, resbuf, buffer, buflen, + &errno H_ERRNO_VAR)); /* The status is NSS_STATUS_TRYAGAIN and errno is ERANGE the provided buffer is too small. In this case we should give @@ -227,7 +232,7 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, break; no_more = __nss_next (&nip, REENTRANT_NAME_STRING, - (void **) &fct, status, 0); + &fct.ptr, status, 0); } #ifdef HANDLE_DIGITS_DOTS @@ -262,7 +267,7 @@ OLD (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer, size_t buflen, LOOKUP_TYPE **result H_ERRNO_PARM) { int ret = INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, resbuf, buffer, - buflen, result H_ERRNO_VAR); + buflen, result H_ERRNO_VAR); if (ret != 0) ret = -1; diff --git a/nss/getXXent.c b/nss/getXXent.c index ebe6fff5f0..0a13b79d87 100644 --- a/nss/getXXent.c +++ b/nss/getXXent.c @@ -70,7 +70,11 @@ LOOKUP_TYPE * GETFUNC_NAME (void) { static size_t buffer_size; - static LOOKUP_TYPE resbuf; + static union + { + LOOKUP_TYPE l; + void *ptr; + } resbuf; LOOKUP_TYPE *result; int save; @@ -79,7 +83,7 @@ GETFUNC_NAME (void) result = (LOOKUP_TYPE *) __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME), - (void **) &resbuf, &buffer, BUFLEN, &buffer_size, + &resbuf.ptr, &buffer, BUFLEN, &buffer_size, H_ERRNO_VAR); save = errno; diff --git a/nss/getnssent_r.c b/nss/getnssent_r.c index c1f8965363..7545b80c4a 100644 --- a/nss/getnssent_r.c +++ b/nss/getnssent_r.c @@ -53,7 +53,11 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct, service_user **last_nip, int stayopen, int *stayopen_tmp, int res) { - setent_function fct; + union + { + setent_function f; + void *ptr; + } fct; int no_more; if (res && (_res.options & RES_INIT) == 0 @@ -65,7 +69,7 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct, /* Cycle through the services and run their `setXXent' functions until we find an available service. */ - no_more = setup (func_name, lookup_fct, (void **) &fct, nip, + no_more = setup (func_name, lookup_fct, &fct.ptr, nip, startp, 1); while (! no_more) { @@ -73,11 +77,11 @@ __nss_setent (const char *func_name, db_lookup_function lookup_fct, enum nss_status status; if (stayopen_tmp) - status = DL_CALL_FCT (fct, (*stayopen_tmp)); + status = DL_CALL_FCT (fct.f, (*stayopen_tmp)); else - status = DL_CALL_FCT (fct, (0)); + status = DL_CALL_FCT (fct.f, (0)); - no_more = __nss_next (nip, func_name, (void **) &fct, + no_more = __nss_next (nip, func_name, &fct.ptr, status, 0); if (is_last_nip) *last_nip = *nip; @@ -93,7 +97,11 @@ __nss_endent (const char *func_name, db_lookup_function lookup_fct, service_user **nip, service_user **startp, service_user **last_nip, int res) { - endent_function fct; + union + { + endent_function f; + void *ptr; + } fct; int no_more; if (res && (_res.options & RES_INIT) == 0 @@ -104,17 +112,17 @@ __nss_endent (const char *func_name, db_lookup_function lookup_fct, } /* Cycle through all the services and run their endXXent functions. */ - no_more = setup (func_name, lookup_fct, (void **) &fct, nip, startp, 1); + no_more = setup (func_name, lookup_fct, &fct.ptr, nip, startp, 1); while (! no_more) { /* Ignore status, we force check in __NSS_NEXT. */ - DL_CALL_FCT (fct, ()); + DL_CALL_FCT (fct.f, ()); if (*nip == *last_nip) /* We have processed all services which were used. */ break; - no_more = __nss_next (nip, func_name, (void **) &fct, 0, 1); + no_more = __nss_next (nip, func_name, &fct.ptr, 0, 1); } *last_nip = *nip = NULL; } @@ -129,7 +137,11 @@ __nss_getent_r (const char *getent_func_name, void *resbuf, char *buffer, size_t buflen, void **result, int *h_errnop) { - getent_function fct; + union + { + getent_function f; + void *ptr; + } fct; int no_more; enum nss_status status; @@ -147,14 +159,14 @@ __nss_getent_r (const char *getent_func_name, /* Run through available functions, starting with the same function last run. We will repeat each function as long as it succeeds, and then go on to the next service action. */ - no_more = setup (getent_func_name, lookup_fct, (void **) &fct, nip, + no_more = setup (getent_func_name, lookup_fct, &fct.ptr, nip, startp, 0); while (! no_more) { int is_last_nip = *nip == *last_nip; - status = DL_CALL_FCT (fct, - (resbuf, buffer, buflen, &errno, &h_errno)); + status = DL_CALL_FCT (fct.f, + (resbuf, buffer, buflen, &errno, &h_errno)); /* The the status is NSS_STATUS_TRYAGAIN and errno is ERANGE the provided buffer is too small. In this case we should give @@ -168,7 +180,7 @@ __nss_getent_r (const char *getent_func_name, do { - no_more = __nss_next (nip, getent_func_name, (void **) &fct, + no_more = __nss_next (nip, getent_func_name, &fct.ptr, status, 0); if (is_last_nip) @@ -177,17 +189,21 @@ __nss_getent_r (const char *getent_func_name, if (! no_more) { /* Call the `setXXent' function. This wasn't done before. */ - setent_function sfct; + union + { + setent_function f; + void *ptr; + } sfct; no_more = __nss_lookup (nip, setent_func_name, - (void **) &sfct); + &sfct.ptr); if (! no_more) { if (stayopen_tmp) - status = DL_CALL_FCT (sfct, (*stayopen_tmp)); + status = DL_CALL_FCT (sfct.f, (*stayopen_tmp)); else - status = DL_CALL_FCT (sfct, (0)); + status = DL_CALL_FCT (sfct.f, (0)); } else status = NSS_STATUS_NOTFOUND; diff --git a/sunrpc/netname.c b/sunrpc/netname.c index dd275f133c..07cddb7c38 100644 --- a/sunrpc/netname.c +++ b/sunrpc/netname.c @@ -147,32 +147,36 @@ netname2user (const char netname[MAXNETNAMELEN + 1], uid_t * uidp, gid_t * gidp, static service_user *startp; static netname2user_function start_fct; service_user *nip; - netname2user_function fct; + union + { + netname2user_function f; + void *ptr; + } fct; enum nss_status status = NSS_STATUS_UNAVAIL; int no_more; if (startp == NULL) { - no_more = __nss_publickey_lookup (&nip, "netname2user", (void **) &fct); + no_more = __nss_publickey_lookup (&nip, "netname2user", &fct.ptr); if (no_more) startp = (service_user *) - 1; else { startp = nip; - start_fct = fct; + start_fct = fct.f; } } else { - fct = start_fct; + fct.f = start_fct; no_more = (nip = startp) == (service_user *) - 1; } while (!no_more) { - status = (*fct) (netname, uidp, gidp, gidlenp, gidlist); + status = (*fct.f) (netname, uidp, gidp, gidlenp, gidlist); - no_more = __nss_next (&nip, "netname2user", (void **) &fct, status, 0); + no_more = __nss_next (&nip, "netname2user", &fct.ptr, status, 0); } return status == NSS_STATUS_SUCCESS; diff --git a/sunrpc/publickey.c b/sunrpc/publickey.c index ecf57bc90c..5b95edf632 100644 --- a/sunrpc/publickey.c +++ b/sunrpc/publickey.c @@ -42,32 +42,36 @@ getpublickey (const char *name, char *key) static service_user *startp; static public_function start_fct; service_user *nip; - public_function fct; + union + { + public_function f; + void *ptr; + } fct; enum nss_status status = NSS_STATUS_UNAVAIL; int no_more; if (startp == NULL) { - no_more = __nss_publickey_lookup (&nip, "getpublickey", (void **) &fct); + no_more = __nss_publickey_lookup (&nip, "getpublickey", &fct.ptr); if (no_more) startp = (service_user *) -1; else { startp = nip; - start_fct = fct; + start_fct = fct.f; } } else { - fct = start_fct; + fct.f = start_fct; no_more = (nip = startp) == (service_user *) -1; } while (! no_more) { - status = (*fct) (name, key, &errno); + status = (*fct.f) (name, key, &errno); - no_more = __nss_next (&nip, "getpublickey", (void **) &fct, status, 0); + no_more = __nss_next (&nip, "getpublickey", &fct.ptr, status, 0); } return status == NSS_STATUS_SUCCESS; @@ -81,32 +85,36 @@ getsecretkey (const char *name, char *key, const char *passwd) static service_user *startp; static secret_function start_fct; service_user *nip; - secret_function fct; + union + { + secret_function f; + void *ptr; + } fct; enum nss_status status = NSS_STATUS_UNAVAIL; int no_more; if (startp == NULL) { - no_more = __nss_publickey_lookup (&nip, "getsecretkey", (void **) &fct); + no_more = __nss_publickey_lookup (&nip, "getsecretkey", &fct.ptr); if (no_more) startp = (service_user *) -1; else { startp = nip; - start_fct = fct; + start_fct = fct.f; } } else { - fct = start_fct; + fct.f = start_fct; no_more = (nip = startp) == (service_user *) -1; } while (! no_more) { - status = (*fct) (name, key, passwd, &errno); + status = (*fct.f) (name, key, passwd, &errno); - no_more = __nss_next (&nip, "getsecretkey", (void **) &fct, status, 0); + no_more = __nss_next (&nip, "getsecretkey", &fct.ptr, status, 0); } return status == NSS_STATUS_SUCCESS; -- cgit 1.4.1