From: Ken Raeburn Date: Mon, 30 Dec 2002 19:46:21 +0000 (+0000) Subject: * gss-misc.c (send_token, recv_token): Open-code the math to send and receive X-Git-Tag: krb5-1.3-alpha1~203 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4aa56f2b15e29b6f429c563c61e30771852b22f1;p=krb5.git * gss-misc.c (send_token, recv_token): Open-code the math to send and receive the length as four bytes in network order, rather than using the first four bytes of a size_t. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15071 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/appl/gss-sample/ChangeLog b/src/appl/gss-sample/ChangeLog index eb8135fea..08e8491f5 100644 --- a/src/appl/gss-sample/ChangeLog +++ b/src/appl/gss-sample/ChangeLog @@ -1,3 +1,9 @@ +2002-12-30 Ken Raeburn + + * gss-misc.c (send_token, recv_token): Open-code the math to send + and receive the length as four bytes in network order, rather than + using the first four bytes of a size_t. + 2002-08-29 Ken Raeburn * Makefile.in: Revert $(S)=>/ change, for Windows support. diff --git a/src/appl/gss-sample/gss-misc.c b/src/appl/gss-sample/gss-misc.c index a9417c2e7..9a2dd0b34 100644 --- a/src/appl/gss-sample/gss-misc.c +++ b/src/appl/gss-sample/gss-misc.c @@ -122,6 +122,7 @@ int send_token(s, flags, tok) { int len, ret; unsigned char char_flags = (unsigned char) flags; + unsigned char lenbuf[4]; ret = write_all(s, (char *)&char_flags, 1); if (ret != 1) { @@ -129,9 +130,14 @@ int send_token(s, flags, tok) return -1; } - len = htonl(tok->length); + if (tok->length > 0xffffffffUL) + abort(); + lenbuf[0] = (tok->length >> 24) & 0xff; + lenbuf[1] = (tok->length >> 16) & 0xff; + lenbuf[2] = (tok->length >> 8) & 0xff; + lenbuf[3] = tok->length & 0xff; - ret = write_all(s, (char *) &len, 4); + ret = write_all(s, lenbuf, 4); if (ret < 0) { perror("sending token length"); return -1; @@ -188,6 +194,7 @@ int recv_token(s, flags, tok) { int ret; unsigned char char_flags; + unsigned char lenbuf[4]; ret = read_all(s, (char *) &char_flags, 1); if (ret < 0) { @@ -201,7 +208,7 @@ int recv_token(s, flags, tok) *flags = (int) char_flags; } - ret = read_all(s, (char *) &tok->length, 4); + ret = read_all(s, lenbuf, 4); if (ret < 0) { perror("reading token length"); return -1; @@ -212,8 +219,11 @@ int recv_token(s, flags, tok) ret, 4); return -1; } - - tok->length = ntohl(tok->length); + + tok->length = ((lenbuf[0] << 24) + | (lenbuf[1] << 16) + | (lenbuf[2] << 8) + | lenbuf[3]); tok->value = (char *) malloc(tok->length ? tok->length : 1); if (tok->length && tok->value == NULL) { if (display_file)