From 46a891bb4021a9a1b62ec784ea9819ad01251ce5 Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Thu, 6 Dec 2001 18:27:06 +0000 Subject: [PATCH] * krcp.c, krlogin.c, krlogind.c, krsh.c, krshd.c, login.c, setenv.c, v4rcp.c: Signed v.s unsigned int cleanup. * defines.h: rcmd_stream_{read,write} take size_t as length argument. * kcmd.c: Use GETSOCKNAME_ARG3_TYPE instead of assuming int. input and output handler take size_t as length argument instead of int. Other signed vs. unsigned fixes. * configure.in: Add KRB5_GETSOCKNAME_ARGS. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14050 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/ChangeLog | 13 ++++++++++ src/appl/bsd/configure.in | 1 + src/appl/bsd/defines.h | 4 +-- src/appl/bsd/kcmd.c | 51 +++++++++++++++++++++------------------ src/appl/bsd/krcp.c | 13 ++++++---- src/appl/bsd/krlogin.c | 18 ++++++++------ src/appl/bsd/krlogind.c | 2 +- src/appl/bsd/krsh.c | 6 ++--- src/appl/bsd/krshd.c | 8 +++--- src/appl/bsd/login.c | 2 +- src/appl/bsd/setenv.c | 2 +- src/appl/bsd/v4rcp.c | 28 ++++++++++++--------- 12 files changed, 88 insertions(+), 60 deletions(-) diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index 55467e794..5b8bef8de 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,3 +1,16 @@ +2001-12-06 Ezra Peisach + + * krcp.c, krlogin.c, krlogind.c, krsh.c, krshd.c, login.c, + setenv.c, v4rcp.c: Signed v.s unsigned int cleanup. + + * defines.h: rcmd_stream_{read,write} take size_t as length argument. + + * kcmd.c: Use GETSOCKNAME_ARG3_TYPE instead of assuming int. input + and output handler take size_t as length argument instead of + int. Other signed vs. unsigned fixes. + + * configure.in: Add KRB5_GETSOCKNAME_ARGS. + 2001-11-06 Sam Hartman * kcmd.c: Define storage for our key usages diff --git a/src/appl/bsd/configure.in b/src/appl/bsd/configure.in index 7471d7d45..345f31a91 100644 --- a/src/appl/bsd/configure.in +++ b/src/appl/bsd/configure.in @@ -92,6 +92,7 @@ CHECK_DIRENT CHECK_WAIT_TYPE AC_CHECK_HEADER(termios.h,AC_CHECK_FUNC(cfsetispeed,AC_DEFINE(POSIX_TERMIOS))) CHECK_UTMP +KRB5_GETSOCKNAME_ARGS dnl dnl Check for where the BSD rlogin, rcp, and rsh programs live. dnl diff --git a/src/appl/bsd/defines.h b/src/appl/bsd/defines.h index 62f6882bc..c32d84080 100644 --- a/src/appl/bsd/defines.h +++ b/src/appl/bsd/defines.h @@ -34,8 +34,8 @@ extern int kcmd (int *sock, char **ahost, int /* u_short */ rport, enum kcmd_proto *protonum /* input and output */ ); -extern int rcmd_stream_read (int fd, char *buf, int len, int secondary); -extern int rcmd_stream_write (int fd, char *buf, int len, int secondary); +extern int rcmd_stream_read (int fd, char *buf, size_t len, int secondary); +extern int rcmd_stream_write (int fd, char *buf, size_t len, int secondary); extern int getport (int *); extern void rcmd_stream_init_krb5 (krb5_keyblock *in_keyblock, diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c index 7e787bf58..4c8ca7a23 100644 --- a/src/appl/bsd/kcmd.c +++ b/src/appl/bsd/kcmd.c @@ -105,6 +105,9 @@ char *default_service = "host"; #define KCMD_KEYUSAGE 1026 /* Key usage used with 3des or any old-protocol enctype*/ /* New protocol enctypes that use cipher state have keyusage defined later*/ +#ifndef GETSOCKNAME_ARG3_TYPE +#define GETSOCKNAME_ARG3_TYPE int +#endif /* * Note that the encrypted rlogin packets take the form of a four-byte @@ -126,17 +129,17 @@ static krb5_keyusage enc_keyusage_i[2], enc_keyusage_o[2]; static krb5_data encivec_i[2], encivec_o[2]; static krb5_keyblock *keyblock; /* key for encrypt/decrypt */ -static int (*input)(int, char *, int, int); -static int (*output)(int, char *, int, int); +static int (*input)(int, char *, size_t, int); +static int (*output)(int, char *, size_t, int); static char storage[2*RCMD_BUFSIZ]; /* storage for the decryption */ -static int nstored = 0; +static size_t nstored = 0; static char *store_ptr = storage; -static int twrite(int, char *, int, int); -static int v5_des_read(int, char *, int, int), - v5_des_write(int, char *, int, int); +static int twrite(int, char *, size_t, int); +static int v5_des_read(int, char *, size_t, int), + v5_des_write(int, char *, size_t, int); #ifdef KRB5_KRB4_COMPAT -static int v4_des_read(int, char *, int, int), - v4_des_write(int, char *, int, int); +static int v4_des_read(int, char *, size_t, int), + v4_des_write(int, char *, size_t, int); static C_Block v4_session; static int right_justify; #endif @@ -192,7 +195,7 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, krb5_error_code status; krb5_ap_rep_enc_part *rep_ret; krb5_error *error = 0; - int sin_len; + GETSOCKNAME_ARG3_TYPE sin_len; krb5_ccache cc; krb5_data outbuf; krb5_flags options = authopts; @@ -431,7 +434,8 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, if (!suppress_err) { fprintf(stderr, "Server returned error code %d (%s)\n", error->error, - error_message(ERROR_TABLE_BASE_krb5 + error->error)); + error_message(ERROR_TABLE_BASE_krb5 + + (int) error->error)); if (error->text.length) { fprintf(stderr, "Error text sent from server: %s\n", error->text.data); @@ -553,7 +557,8 @@ k4cmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, ticket, service, realm, char c; int lport = START_PORT; struct hostent *hp; - int rc, sin_len; + int rc; + GETSOCKNAME_ARG3_TYPE sin_len; char *host_save; int status; @@ -729,7 +734,7 @@ reread: cc = 'l'; (void) write(2, &cc, 1); if (p != check) - (void) write(2, check, p - check); + (void) write(2, check, (unsigned) (p - check)); } (void) write(2, &c, 1); @@ -769,7 +774,7 @@ getport(alport) { struct sockaddr_in sockin; int s; - int len = sizeof(sockin); + GETSOCKNAME_ARG3_TYPE len = sizeof(sockin); s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) @@ -796,7 +801,7 @@ getport(alport) } static int -normal_read (int fd, char *buf, int len, int secondary) +normal_read (int fd, char *buf, size_t len, int secondary) { return read (fd, buf, len); } @@ -930,7 +935,7 @@ void rcmd_stream_init_krb4(session, encrypt_flag, lencheck, justify) int rcmd_stream_read(fd, buf, len, sec) int fd; register char *buf; - int len; + size_t len; int sec; { return (*input)(fd, buf, len, sec); @@ -939,7 +944,7 @@ int rcmd_stream_read(fd, buf, len, sec) int rcmd_stream_write(fd, buf, len, sec) int fd; register char *buf; - int len; + size_t len; int sec; { return (*output)(fd, buf, len, sec); @@ -949,7 +954,7 @@ int rcmd_stream_write(fd, buf, len, sec) static int twrite(fd, buf, len, secondary) int fd; char *buf; - int len; + size_t len; int secondary; { return write((fd == 0) ? 1 : fd, buf, len); @@ -958,7 +963,7 @@ static int twrite(fd, buf, len, secondary) static int v5_des_read(fd, buf, len, secondary) int fd; char *buf; - int len; + size_t len; int secondary; { int nreturned = 0; @@ -1069,7 +1074,7 @@ static int v5_des_read(fd, buf, len, secondary) static int v5_des_write(fd, buf, len, secondary) int fd; char *buf; - int len; + size_t len; int secondary; { krb5_data plain; @@ -1128,7 +1133,7 @@ static int v4_des_read(fd, buf, len, secondary) int fd; char *buf; -int len; +size_t len; int secondary; { int nreturned = 0; @@ -1191,7 +1196,7 @@ int secondary; } (void) pcbc_encrypt((des_cblock *) des_inbuf, (des_cblock *) storage, - (net_len < 8) ? 8 : net_len, + (int) ((net_len < 8) ? 8 : net_len), v4_schedule, &v4_session, DECRYPT); @@ -1222,7 +1227,7 @@ static int v4_des_write(fd, buf, len, secondary) int fd; char *buf; -int len; +size_t len; int secondary; { static char garbage_buf[8]; @@ -1252,7 +1257,7 @@ int secondary; } (void) pcbc_encrypt((des_cblock *) ((len < 8) ? garbage_buf : buf), (des_cblock *) (des_outpkt+4), - (len < 8) ? 8 : len, + (int) ((len < 8) ? 8 : len), v4_schedule, &v4_session, ENCRYPT); diff --git a/src/appl/bsd/krcp.c b/src/appl/bsd/krcp.c index d36d50cd6..5ad6a25a1 100644 --- a/src/appl/bsd/krcp.c +++ b/src/appl/bsd/krcp.c @@ -127,7 +127,7 @@ int userid; int port = 0; struct buffer { - int cnt; + unsigned int cnt; char *buf; }; @@ -150,7 +150,7 @@ int main(argc, argv) char *targ, *host, *src; char *suser, *tuser, *thost; int i; - int cmdsiz = 30; + unsigned int cmdsiz = 30; char buf[RCP_BUFSIZ], cmdbuf[30]; char *cmd = cmdbuf; struct servent *sp; @@ -770,7 +770,8 @@ void source(argc, argv) struct stat stb; static struct buffer buffer; struct buffer *bp; - int x, readerr, f, amt; + int x, readerr, f; + unsigned int amt; off_t i; char buf[RCP_BUFSIZ]; @@ -935,7 +936,7 @@ int response() *cp++ = c; } while (cp < &rbuf[RCP_BUFSIZ] && c != '\n'); if (iamremote == 0) - (void) write(2, rbuf, cp - rbuf); + (void) write(2, rbuf, (unsigned) (cp - rbuf)); errs++; if (resp == 1) return (-1); @@ -987,7 +988,9 @@ void sink(argc, argv) mode_t mask = umask(0); off_t i, j; char *targ, *whopp, *cp; - int of, wrerr, exists, first, count, amt, size; + int of, wrerr, exists, first; + off_t size; + unsigned int amt, count; struct buffer *bp; static struct buffer buffer; struct stat stb; diff --git a/src/appl/bsd/krlogin.c b/src/appl/bsd/krlogin.c index 60d31f603..783129897 100644 --- a/src/appl/bsd/krlogin.c +++ b/src/appl/bsd/krlogin.c @@ -273,7 +273,7 @@ static void doit(sigset_t *); static int reader(int); static void doit(int); #endif -static int control(char *, int); +static int control(char *, unsigned int); static void sendwindow(void); static void stop(int), echo(int); static void writer(void), done(int); @@ -1137,7 +1137,7 @@ static void writer() } if (!got_esc) { - if (rcmd_stream_write(rem, buf, n_read, 0) == 0) { + if (rcmd_stream_write(rem, buf, (unsigned) n_read, 0) == 0) { prf("line gone"); break; } @@ -1147,7 +1147,7 @@ static void writer() /* This next test is necessary to avoid sending 0 bytes of data in the event that we got just a cmdchar */ if (n_read > 1) { - if (rcmd_stream_write(rem, buf, n_read-1, 0) == 0) { + if (rcmd_stream_write(rem, buf, (unsigned) (n_read-1), 0) == 0) { prf("line gone"); break; } @@ -1227,7 +1227,7 @@ static int read_wrapper(fd,buf,size,got_esc) static char *data_start = tbuf; static char *data_end = tbuf; static int bol = 1; - int return_length = 0; + unsigned int return_length = 0; char c; /* if we have no data buffered, get more */ @@ -1295,7 +1295,7 @@ static void echo(c) *p++ = c; *p++ = '\r'; *p++ = '\n'; - (void) write(1, buf, p - buf); + (void) write(1, buf, (unsigned) (p - buf)); } @@ -1359,7 +1359,7 @@ int signo; static void sendwindow() { char obuf[4 + sizeof (struct winsize)]; - struct winsize *wp = (struct winsize *)(obuf+4); + struct winsize *wp = (struct winsize *)(void *)(obuf+4); obuf[0] = 0377; obuf[1] = 0377; @@ -1498,7 +1498,7 @@ void oob() static int control(cp, n) char *cp; - int n; + unsigned int n; { if ((n >= 5) && (cp[2] == 'o') && (cp[3] == 'o')) { if (server_message(cp[4])) @@ -1526,7 +1526,8 @@ reader(oldmask) #endif { fd_set readset, excset, writeset; - int n, remaining, left; + int n, remaining; + unsigned int left; char *bufp = rcvbuf; char *cp; @@ -1594,6 +1595,7 @@ reader(oldmask) cp[1] == '\377') { left = (rcvbuf+rcvcnt) - cp; n = control(cp, left); + /* |n| <= left */ if (n < 0) { left -= (-n); rcvcnt = 0; diff --git a/src/appl/bsd/krlogind.c b/src/appl/bsd/krlogind.c index a4b835df8..76d1f5397 100644 --- a/src/appl/bsd/krlogind.c +++ b/src/appl/bsd/krlogind.c @@ -1350,7 +1350,7 @@ int default_realm(principal) krb5_principal principal; { char *def_realm; - int realm_length; + unsigned int realm_length; int retval; realm_length = krb5_princ_realm(bsd_context, principal)->length; diff --git a/src/appl/bsd/krsh.c b/src/appl/bsd/krsh.c index bcedf8a00..86893cff5 100644 --- a/src/appl/bsd/krsh.c +++ b/src/appl/bsd/krsh.c @@ -321,7 +321,7 @@ main(argc, argv0) cc += strlen(*ap) + 1; if (encrypt_flag) cc += 3; - cp = args = (char *) malloc(cc); + cp = args = (char *) malloc((unsigned) cc); if (encrypt_flag) { strcpy(args, "-x "); cp += 3; @@ -561,7 +561,7 @@ main(argc, argv0) if ((errno != EWOULDBLOCK) && (errno != EAGAIN)) FD_CLR(rfd2, &readfrom); } else - (void) write(2, buf, cc); + (void) write(2, buf, (unsigned) cc); } if (FD_ISSET(rem, &ready)) { errno = 0; @@ -570,7 +570,7 @@ main(argc, argv0) if ((errno != EWOULDBLOCK) && (errno != EAGAIN)) FD_CLR(rem, &readfrom); } else - (void) write(1, buf, cc); + (void) write(1, buf, (unsigned) cc); } } while (FD_ISSET(rem, &readfrom) || FD_ISSET(rfd2, &readfrom)); if (nflag == 0) diff --git a/src/appl/bsd/krshd.c b/src/appl/bsd/krshd.c index bc0cdc592..56fefc99a 100644 --- a/src/appl/bsd/krshd.c +++ b/src/appl/bsd/krshd.c @@ -1276,7 +1276,7 @@ if(port) shutdown(s, 1+1); FD_CLR(pv[0], &readfrom); } else { - (void) rcmd_stream_write(s, buf, cc, 1); + (void) rcmd_stream_write(s, buf, (unsigned) cc, 1); } } if (FD_ISSET(pw[0], &ready)) { @@ -1287,7 +1287,7 @@ if(port) shutdown(f, 1+1); FD_CLR(pw[0], &readfrom); } else { - (void) rcmd_stream_write(f, buf, cc, 0); + (void) rcmd_stream_write(f, buf, (unsigned) cc, 0); } } if (port&&FD_ISSET(s, &ready)) { @@ -1314,7 +1314,7 @@ if(port) FD_CLR(f, &readfrom); } else { int wcc; - wcc = write(px[1], buf, cc); + wcc = write(px[1], buf, (unsigned) cc); if (wcc == -1) { /* pipe closed, don't read any more */ /* might check for EPIPE */ @@ -1780,7 +1780,7 @@ int default_realm(principal) krb5_principal principal; { char *def_realm; - int realm_length; + unsigned int realm_length; int retval; realm_length = krb5_princ_realm(bsd_context, principal)->length; diff --git a/src/appl/bsd/login.c b/src/appl/bsd/login.c index 9cf6a75bd..6ee629dd3 100644 --- a/src/appl/bsd/login.c +++ b/src/appl/bsd/login.c @@ -2130,7 +2130,7 @@ void checknologin() if ((fd = open(NOLOGIN, O_RDONLY, 0)) >= 0) { while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) - (void)write(fileno(stdout), tbuf, nchars); + (void)write(fileno(stdout), tbuf, (unsigned) nchars); sleepexit(0); } } diff --git a/src/appl/bsd/setenv.c b/src/appl/bsd/setenv.c index d5d0110ce..84e3508c5 100644 --- a/src/appl/bsd/setenv.c +++ b/src/appl/bsd/setenv.c @@ -151,7 +151,7 @@ _findenv(name, offset) int *offset; { extern char **environ; - register int len; + register unsigned int len; register char **P, *C; for (C = name, len = 0; *C && *C != '='; ++C, ++len); diff --git a/src/appl/bsd/v4rcp.c b/src/appl/bsd/v4rcp.c index 94a5eb153..88870cc4b 100644 --- a/src/appl/bsd/v4rcp.c +++ b/src/appl/bsd/v4rcp.c @@ -160,7 +160,7 @@ static kstream kstream_create_from_fd(read_fd, write_fd, sched, session) static int kstream_read(krem, buf, len) kstream krem; char *buf; - int len; + unsigned int len; { if(krem->encrypting) { /* when we get a length, we have to read the whole block. However, @@ -189,7 +189,7 @@ static int kstream_read(krem, buf, len) int cc; unsigned char clen[4]; unsigned int x = 0; - int sz, off; + unsigned int sz, off; cc = read(krem->read_fd, clen, 4); if (cc != 4) return cc; @@ -197,7 +197,7 @@ static int kstream_read(krem, buf, len) x <<= 8; x += clen[1] & 0xff; x <<= 8; x += clen[2] & 0xff; x <<= 8; x += clen[3] & 0xff; - sz = (x + 7) & ~7; + sz = (x + 7) & (~7U); if (krem->retbuflen < sz) { if (krem->retbuflen == 0) @@ -219,7 +219,7 @@ static int kstream_read(krem, buf, len) /* decrypt it */ des_pcbc_encrypt ((des_cblock *)krem->retbuf, (des_cblock *)krem->retbuf, - sz, *krem->sched, krem->ivec, + (int) sz, *krem->sched, krem->ivec, DECRYPT); /* now retbuf has sz bytes, return len or x of them to the user */ @@ -242,12 +242,12 @@ static int kstream_read(krem, buf, len) static int kstream_write(krem, buf, len) kstream krem; char *buf; - int len; + unsigned int len; { if (krem->encrypting) { unsigned long x; int st; - int outlen = (len + 7) & (~7); + unsigned int outlen = (len + 7) & (~7U); if (krem->writelen < outlen) { if (krem->writelen == 0) { @@ -261,7 +261,7 @@ static int kstream_write(krem, buf, len) krem->writelen = outlen; } - outlen = (len + 7) & (~7); + outlen = (len + 7) & (~7U); memcpy(krem->inbuf, buf, len); krb5_random_confounder(outlen-len, krem->inbuf+len); @@ -275,7 +275,8 @@ static int kstream_write(krem, buf, len) if (x) abort (); /* memset(outbuf+4+4, 0x42, BUFSIZ); */ - st = des_pcbc_encrypt ((des_cblock *)buf, (des_cblock *)(krem->outbuf+4+4), outlen, + st = des_pcbc_encrypt ((des_cblock *)buf, (des_cblock *)(krem->outbuf+4+4), + (int) outlen, *krem->sched, krem->ivec, ENCRYPT); if (st) abort(); @@ -486,7 +487,8 @@ void source(argc, argv) struct stat stb; static struct buffer buffer; struct buffer *bp; - int x, readerr, f, amt; + int x, readerr, f; + unsigned int amt; off_t i; char buf[BUFSIZ]; @@ -648,7 +650,7 @@ int response() *cp++ = c; } while (cp < &rbuf[BUFSIZ] && c != '\n'); if (iamremote == 0) - (void) write(2, rbuf, cp - rbuf); + (void) write(2, rbuf, (unsigned) (cp - rbuf)); errs++; if (resp == 1) return (-1); @@ -695,13 +697,15 @@ void sink(argc, argv) { off_t i, j; char *targ, *whopp, *cp; - int of, mode, wrerr, exists, first, count, amt; + int of, wrerr, exists, first, amt; + mode_t mode; + unsigned int count; off_t size; struct buffer *bp; static struct buffer buffer; struct stat stb; int targisdir = 0; - int mask = umask(0); + mode_t mask = umask(0); char *myargv[1]; char cmdbuf[BUFSIZ], nambuf[BUFSIZ]; int setimes = 0; -- 2.26.2