Make share_got_pkt_from_server take a const pointer.

It was horrible - even if harmless in practice - that it wrote the
NATed channel id over its input buffer, and I think it's worth the
extra memory management to avoid doing that.
This commit is contained in:
Simon Tatham 2018-06-06 07:19:57 +01:00
Родитель 452114c3d3
Коммит 61a972c332
2 изменённых файлов: 8 добавлений и 4 удалений

2
ssh.h
Просмотреть файл

@ -27,7 +27,7 @@ extern Socket ssh_connection_sharing_init(
void **state);
int ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
void share_got_pkt_from_server(void *ctx, int type,
unsigned char *pkt, int pktlen);
const void *pkt, int pktlen);
void share_activate(void *state, const char *server_verstring);
void sharestate_free(void *state);
int share_ndownstreams(void *state);

Просмотреть файл

@ -1129,8 +1129,9 @@ void share_setup_x11_channel(void *csv, void *chanv,
}
void share_got_pkt_from_server(void *csv, int type,
unsigned char *pkt, int pktlen)
const void *vpkt, int pktlen)
{
const unsigned char *pkt = (const unsigned char *)vpkt;
struct ssh_sharing_connstate *cs = (struct ssh_sharing_connstate *)csv;
struct share_globreq *globreq;
size_t id_pos;
@ -1203,8 +1204,11 @@ void share_got_pkt_from_server(void *csv, int type,
/*
* The normal case: this id refers to an open channel.
*/
PUT_32BIT(pkt + id_pos, chan->downstream_id);
send_packet_to_downstream(cs, type, pkt, pktlen, chan);
unsigned char *rewritten = snewn(pktlen, unsigned char);
memcpy(rewritten, pkt, pktlen);
PUT_32BIT(rewritten + id_pos, chan->downstream_id);
send_packet_to_downstream(cs, type, rewritten, pktlen, chan);
sfree(rewritten);
/*
* Update the channel state, for messages that need it.