diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2000-08-23 00:05:29 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2000-08-23 00:05:29 +0000 |
| commit | 1e784a779213fe04c82bc5397f8d1d32ccced8f1 (patch) | |
| tree | 24b90428753d54b13fc3186f2097feeb01f319dc /lib/libc | |
| parent | 4fcb0747ad0490ce614db17b2c10ad4c2c83c942 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/rpc/netname.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/libc/rpc/netname.c b/lib/libc/rpc/netname.c index 22167bee86cc..cec14df72ab5 100644 --- a/lib/libc/rpc/netname.c +++ b/lib/libc/rpc/netname.c @@ -26,6 +26,8 @@ * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 + * + * $FreeBSD$ */ #if !defined(lint) && defined(SCCSIDS) static char sccsid[] = "@(#)netname.c 1.8 91/03/11 Copyr 1986 Sun Micro"; @@ -47,10 +49,11 @@ static char sccsid[] = "@(#)netname.c 1.8 91/03/11 Copyr 1986 Sun Micro"; #include <rpcsvc/ypclnt.h> #endif #include <ctype.h> +#include <limits.h> +#include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include <stdio.h> +#include <unistd.h> #ifndef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 256 @@ -59,6 +62,19 @@ static char sccsid[] = "@(#)netname.c 1.8 91/03/11 Copyr 1986 Sun Micro"; #define NGROUPS 16 #endif +#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) + +#define TYPE_SIGNED(type) (((type) -1) < 0) + +/* +** 302 / 1000 is log10(2.0) rounded up. +** Subtract one for the sign bit if the type is signed; +** add one for integer division truncation; +** add one more for a minus sign if the type is signed. +*/ +#define INT_STRLEN_MAXIMUM(type) \ + ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type)) + static char *OPSYS = "unix"; /* @@ -90,15 +106,13 @@ user2netname(netname, uid, domain) { char *dfltdom; -#define MAXIPRINT (11) /* max length of printed integer */ - if (domain == NULL) { if (_rpc_get_default_domain(&dfltdom) != 0) { return (0); } domain = dfltdom; } - if (strlen(domain) + 1 + MAXIPRINT > MAXNETNAMELEN) { + if (strlen(domain) + 1 + INT_STRLEN_MAXIMUM(u_long) + 1 + strlen(OPSYS) > MAXNETNAMELEN) { return (0); } (void) sprintf(netname, "%s.%ld@%s", OPSYS, (u_long)uid, domain); @@ -128,7 +142,7 @@ host2netname(netname, host, domain) (void) gethostname(hostname, sizeof(hostname)); host = hostname; } - if (strlen(domain) + 1 + strlen(host) > MAXNETNAMELEN) { + if (strlen(domain) + 1 + strlen(host) + 1 + strlen(OPSYS) > MAXNETNAMELEN) { return (0); } (void) sprintf(netname, "%s.%s@%s", OPSYS, host, domain); |
