mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-18 19:41:01 -05:00
Stop using unqualified {GET,PUT}_32BIT.
Those were a reasonable abbreviation when the code almost never had to deal with little-endian numbers, but they've crept into enough places now (e.g. the ECC formatting) that I think I'd now prefer that every use of the integer read/write macros was clearly marked with its endianness. So all uses of GET_??BIT and PUT_??BIT are now qualified. The special versions in x11fwd.c, which used variable endianness because so does the X11 protocol, are suffixed _X11 to make that clear, and where that pushed line lengths over 80 characters I've taken the opportunity to name a local variable to remind me of what that extra parameter actually does.
This commit is contained in:
24
x11fwd.c
24
x11fwd.c
@ -12,10 +12,10 @@
|
||||
#include "sshchan.h"
|
||||
#include "tree234.h"
|
||||
|
||||
#define GET_16BIT(endian, cp) \
|
||||
#define GET_16BIT_X11(endian, cp) \
|
||||
(endian=='B' ? GET_16BIT_MSB_FIRST(cp) : GET_16BIT_LSB_FIRST(cp))
|
||||
|
||||
#define PUT_16BIT(endian, cp, val) \
|
||||
#define PUT_16BIT_X11(endian, cp, val) \
|
||||
(endian=='B' ? PUT_16BIT_MSB_FIRST(cp, val) : PUT_16BIT_LSB_FIRST(cp, val))
|
||||
|
||||
const char *const x11_authnames[] = {
|
||||
@ -881,7 +881,7 @@ static void x11_send_init_error(struct X11Connection *xconn,
|
||||
reply[0] = 0; /* failure */
|
||||
reply[1] = msglen; /* length of reason string */
|
||||
memcpy(reply + 2, xconn->firstpkt + 2, 4); /* major/minor proto vsn */
|
||||
PUT_16BIT(xconn->firstpkt[0], reply + 6, msgsize >> 2);/* data len */
|
||||
PUT_16BIT_X11(xconn->firstpkt[0], reply + 6, msgsize >> 2);/* data len */
|
||||
memset(reply + 8, 0, msgsize);
|
||||
memcpy(reply + 8, full_message, msglen);
|
||||
sshfwd_write(xconn->c, reply, 8 + msgsize);
|
||||
@ -930,8 +930,9 @@ static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len)
|
||||
* strings, do so now.
|
||||
*/
|
||||
if (!xconn->auth_protocol) {
|
||||
xconn->auth_plen = GET_16BIT(xconn->firstpkt[0], xconn->firstpkt + 6);
|
||||
xconn->auth_dlen = GET_16BIT(xconn->firstpkt[0], xconn->firstpkt + 8);
|
||||
char endian = xconn->firstpkt[0];
|
||||
xconn->auth_plen = GET_16BIT_X11(endian, xconn->firstpkt + 6);
|
||||
xconn->auth_dlen = GET_16BIT_X11(endian, xconn->firstpkt + 8);
|
||||
xconn->auth_psize = (xconn->auth_plen + 3) & ~3;
|
||||
xconn->auth_dsize = (xconn->auth_dlen + 3) & ~3;
|
||||
/* Leave room for a terminating zero, to make our lives easier. */
|
||||
@ -967,9 +968,10 @@ static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len)
|
||||
int socketdatalen;
|
||||
char new_peer_addr[32];
|
||||
int new_peer_port;
|
||||
char endian = xconn->firstpkt[0];
|
||||
|
||||
protomajor = GET_16BIT(xconn->firstpkt[0], xconn->firstpkt + 2);
|
||||
protominor = GET_16BIT(xconn->firstpkt[0], xconn->firstpkt + 4);
|
||||
protomajor = GET_16BIT_X11(endian, xconn->firstpkt + 2);
|
||||
protominor = GET_16BIT_X11(endian, xconn->firstpkt + 4);
|
||||
|
||||
assert(!xconn->s);
|
||||
|
||||
@ -1177,10 +1179,10 @@ void *x11_make_greeting(int endian, int protomajor, int protominor,
|
||||
greeting = snewn(greeting_len, unsigned char);
|
||||
memset(greeting, 0, greeting_len);
|
||||
greeting[0] = endian;
|
||||
PUT_16BIT(endian, greeting+2, protomajor);
|
||||
PUT_16BIT(endian, greeting+4, protominor);
|
||||
PUT_16BIT(endian, greeting+6, authnamelen);
|
||||
PUT_16BIT(endian, greeting+8, authdatalen);
|
||||
PUT_16BIT_X11(endian, greeting+2, protomajor);
|
||||
PUT_16BIT_X11(endian, greeting+4, protominor);
|
||||
PUT_16BIT_X11(endian, greeting+6, authnamelen);
|
||||
PUT_16BIT_X11(endian, greeting+8, authdatalen);
|
||||
memcpy(greeting+12, authname, authnamelen);
|
||||
memcpy(greeting+12+authnamelen_pad, authdata, authdatalen);
|
||||
|
||||
|
Reference in New Issue
Block a user