pr->auth_data = snewn(pr->auth_dsize, char);
pr->auth_data = snewn(pr->auth_dsize, unsigned char);
int x11_send(Socket s, char *data, int len){    struct X11Private *pr = (struct X11Private *) sk_get_private_ptr(s);    if (s == NULL)	return 0;    /*     * Read the first packet.     */    while (len > 0 && pr->data_read < 12)	pr->firstpkt[pr->data_read++] = (unsigned char) (len--, *data++);    if (pr->data_read < 12)	return 0;    /*     * If we have not allocated the auth_protocol and auth_data     * strings, do so now.     */    if (!pr->auth_protocol) {	pr->auth_plen = GET_16BIT(pr->firstpkt[0], pr->firstpkt + 6);	pr->auth_dlen = GET_16BIT(pr->firstpkt[0], pr->firstpkt + 8);	pr->auth_psize = (pr->auth_plen + 3) & ~3;	pr->auth_dsize = (pr->auth_dlen + 3) & ~3;	/* Leave room for a terminating zero, to make our lives easier. */	pr->auth_protocol = snewn(pr->auth_psize + 1, char);	pr->auth_data = snewn(pr->auth_dsize, char);    }    /*     * Read the auth_protocol and auth_data strings.     */    while (len > 0 && pr->data_read < 12 + pr->auth_psize)	pr->auth_protocol[pr->data_read++ - 12] = (len--, *data++);    while (len > 0 && pr->data_read < 12 + pr->auth_psize + pr->auth_dsize)	pr->auth_data[pr->data_read++ - 12 -		      pr->auth_psize] = (unsigned char) (len--, *data++);    if (pr->data_read < 12 + pr->auth_psize + pr->auth_dsize)	return 0;    /*     * If we haven't verified the authentication, do so now.     */    if (!pr->verified) {	char *err;	pr->auth_protocol[pr->auth_plen] = '\0';	/* ASCIZ */	err = x11_verify(pr->peer_ip, pr->peer_port,			 pr->auth, pr->auth_protocol,			 pr->auth_data, pr->auth_dlen);	/*	 * If authentication failed, construct and send an error	 * packet, then terminate the connection.	 */	if (err) {	    char *message;	    int msglen, msgsize;	    unsigned char *reply;	    message = dupprintf("PuTTY X11 proxy: %s", err);	    msglen = strlen(message);	    reply = snewn(8 + msglen+1 + 4, unsigned char); /* include zero */	    msgsize = (msglen + 3) & ~3;	    reply[0] = 0;	       /* failure */	    reply[1] = msglen;	       /* length of reason string */	    memcpy(reply + 2, pr->firstpkt + 2, 4);	/* major/minor proto vsn */	    PUT_16BIT(pr->firstpkt[0], reply + 6, msgsize >> 2);/* data len */	    memset(reply + 8, 0, msgsize);	    memcpy(reply + 8, message, msglen);	    sshfwd_write(pr->c, (char *)reply, 8 + msgsize);	    sshfwd_close(pr->c);	    x11_close(s);	    sfree(reply);	    sfree(message);	    return 0;	}	/*	 * Now we know we're going to accept the connection. Strip	 * the fake auth data, and optionally put real auth data in	 * instead.	 */        {            char realauthdata[64];            int realauthlen = 0;            int authstrlen = strlen(x11_authnames[pr->auth->realproto]);	    unsigned long ip;	    int port;            static const char zeroes[4] = { 0,0,0,0 };            if (pr->auth->realproto == X11_MIT) {                assert(pr->auth->reallen <= lenof(realauthdata));                realauthlen = pr->auth->reallen;                memcpy(realauthdata, pr->auth->realdata, realauthlen);            } else if (pr->auth->realproto == X11_XDM &&		       pr->auth->reallen == 16 &&		       sk_getxdmdata(s, &ip, &port)) {		time_t t;                realauthlen = 24;		memset(realauthdata, 0, 24);		memcpy(realauthdata, pr->auth->realdata, 8);		PUT_32BIT_MSB_FIRST(realauthdata+8, ip);		PUT_16BIT_MSB_FIRST(realauthdata+12, port);		t = time(NULL);		PUT_32BIT_MSB_FIRST(realauthdata+14, t);		des_encrypt_xdmauth(pr->auth->realdata+9,				    (unsigned char *)realauthdata, 24);	    }            /* implement other auth methods here if required */            PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 6, authstrlen);            PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 8, realauthlen);                    sk_write(s, (char *)pr->firstpkt, 12);            if (authstrlen) {                sk_write(s, x11_authnames[pr->auth->realproto], authstrlen);                sk_write(s, zeroes, 3 & (-authstrlen));            }            if (realauthlen) {                sk_write(s, realauthdata, realauthlen);                sk_write(s, zeroes, 3 & (-realauthlen));            }        }	pr->verified = 1;    }    /*     * After initialisation, just copy data simply.     */    return sk_write(s, data, len);}