diff --git a/agentf.c b/agentf.c index 5bac3797..4069fee8 100644 --- a/agentf.c +++ b/agentf.c @@ -39,7 +39,7 @@ static void agentf_callback(void *vctx, void *reply, int replylen); static void agentf_try_forward(agentf *af) { - unsigned datalen, length; + size_t datalen, length; strbuf *message; unsigned char msglen[4]; void *reply; @@ -142,7 +142,7 @@ static void agentf_callback(void *vctx, void *reply, int replylen) } static void agentf_free(Channel *chan); -static int agentf_send(Channel *chan, bool is_stderr, const void *, int); +static size_t agentf_send(Channel *chan, bool is_stderr, const void *, size_t); static void agentf_send_eof(Channel *chan); static char *agentf_log_close_msg(Channel *chan); static void agentf_set_input_wanted(Channel *chan, bool wanted); @@ -196,8 +196,8 @@ static void agentf_free(Channel *chan) sfree(af); } -static int agentf_send(Channel *chan, bool is_stderr, - const void *data, int length) +static size_t agentf_send(Channel *chan, bool is_stderr, + const void *data, size_t length) { assert(chan->vt == &agentf_channelvt); agentf *af = container_of(chan, agentf, chan); diff --git a/be_misc.c b/be_misc.c index 79a6d33c..84d24639 100644 --- a/be_misc.c +++ b/be_misc.c @@ -59,11 +59,10 @@ void backend_socket_log(Seat *seat, LogContext *logctx, } } -void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, int len) +void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, size_t len) { const char *data = (const char *)vdata; - int pos = 0; - int msglen; + size_t pos = 0; const char *nlpos; char *msg, *fullmsg; @@ -88,7 +87,8 @@ void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, int len) /* * Collect the resulting line of data and pass it to plug_log. */ - msglen = bufchain_size(buf); + size_t msglen = bufchain_size(buf); + assert(msglen < ~(size_t)0); msg = snewn(msglen+1, char); bufchain_fetch(buf, msg, msglen); bufchain_consume(buf, msglen); diff --git a/logging.c b/logging.c index 024bb11e..3ffefcf6 100644 --- a/logging.c +++ b/logging.c @@ -31,7 +31,7 @@ static Filename *xlatlognam(Filename *s, char *hostname, int port, * isn't open, buffering data if it's in the process of being * opened asynchronously, etc. */ -static void logwrite(LogContext *ctx, const void *data, int len) +static void logwrite(LogContext *ctx, const void *data, size_t len) { /* * In state L_CLOSED, we call logfopen, which will set the state @@ -45,7 +45,7 @@ static void logwrite(LogContext *ctx, const void *data, int len) bufchain_add(&ctx->queue, data, len); } else if (ctx->state == L_OPEN) { assert(ctx->lgfp); - if (fwrite(data, 1, len, ctx->lgfp) < (size_t)len) { + if (fwrite(data, 1, len, ctx->lgfp) < len) { logfclose(ctx); ctx->state = L_ERROR; lp_eventlog(ctx->lp, "Disabled writing session log " @@ -138,7 +138,7 @@ static void logfopen_callback(void *vctx, int mode) assert(ctx->state != L_OPENING); /* make _sure_ it won't be requeued */ while (bufchain_size(&ctx->queue)) { void *data; - int len; + size_t len; bufchain_prefix(&ctx->queue, &data, &len); logwrite(ctx, data, len); bufchain_consume(&ctx->queue, len); @@ -276,13 +276,13 @@ void logeventf(LogContext *ctx, const char *fmt, ...) * Set of blanking areas must be in increasing order. */ void log_packet(LogContext *ctx, int direction, int type, - const char *texttype, const void *data, int len, + const char *texttype, const void *data, size_t len, int n_blanks, const struct logblank_t *blanks, const unsigned long *seq, unsigned downstream_id, const char *additional_log_text) { - char dumpdata[80], smalldata[5]; - int p = 0, b = 0, omitted = 0; + char dumpdata[128], smalldata[5]; + size_t p = 0, b = 0, omitted = 0; int output_pos = 0; /* NZ if pending output in dumpdata */ if (!(ctx->logtype == LGTYP_SSHRAW || @@ -354,7 +354,7 @@ void log_packet(LogContext *ctx, int direction, int type, /* (Re-)initialise dumpdata as necessary * (start of row, or if we've just stopped omitting) */ if (!output_pos && !omitted) - sprintf(dumpdata, " %08x%*s\r\n", p-(p%16), 1+3*16+2+16, ""); + sprintf(dumpdata, " %08zx%*s\r\n", p-(p%16), 1+3*16+2+16, ""); /* Deal with the current byte. */ if (blktype == PKTLOG_OMIT) { diff --git a/mainchan.c b/mainchan.c index eb9d407c..14712615 100644 --- a/mainchan.c +++ b/mainchan.c @@ -14,7 +14,8 @@ static void mainchan_free(Channel *chan); static void mainchan_open_confirmation(Channel *chan); static void mainchan_open_failure(Channel *chan, const char *errtext); -static int mainchan_send(Channel *chan, bool is_stderr, const void *, int); +static size_t mainchan_send( + Channel *chan, bool is_stderr, const void *, size_t); static void mainchan_send_eof(Channel *chan); static void mainchan_set_input_wanted(Channel *chan, bool wanted); static char *mainchan_log_close_msg(Channel *chan); @@ -362,8 +363,8 @@ static void mainchan_open_failure(Channel *chan, const char *errtext) queue_toplevel_callback(mainchan_open_failure_abort, ctx); } -static int mainchan_send(Channel *chan, bool is_stderr, - const void *data, int length) +static size_t mainchan_send(Channel *chan, bool is_stderr, + const void *data, size_t length) { assert(chan->vt == &mainchan_channelvt); mainchan *mc = container_of(chan, mainchan, chan); diff --git a/misc.c b/misc.c index 81b3cd1f..b7a188dd 100644 --- a/misc.c +++ b/misc.c @@ -307,8 +307,8 @@ char *buildinfo(const char *newline) return strbuf_to_str(buf); } -int nullseat_output( - Seat *seat, bool is_stderr, const void *data, int len) { return 0; } +size_t nullseat_output( + Seat *seat, bool is_stderr, const void *data, size_t len) { return 0; } bool nullseat_eof(Seat *seat) { return true; } int nullseat_get_userpass_input( Seat *seat, prompts_t *p, bufchain *input) { return 0; } diff --git a/misc.h b/misc.h index 1627250b..542c38eb 100644 --- a/misc.h +++ b/misc.h @@ -95,7 +95,7 @@ int base64_decode_atom(const char *atom, unsigned char *out); struct bufchain_granule; struct bufchain_tag { struct bufchain_granule *head, *tail; - int buffersize; /* current amount of buffered data */ + size_t buffersize; /* current amount of buffered data */ void (*queue_idempotent_callback)(IdempotentCallback *ic); IdempotentCallback *ic; @@ -103,14 +103,14 @@ struct bufchain_tag { void bufchain_init(bufchain *ch); void bufchain_clear(bufchain *ch); -int bufchain_size(bufchain *ch); -void bufchain_add(bufchain *ch, const void *data, int len); -void bufchain_prefix(bufchain *ch, void **data, int *len); -void bufchain_consume(bufchain *ch, int len); -void bufchain_fetch(bufchain *ch, void *data, int len); -void bufchain_fetch_consume(bufchain *ch, void *data, int len); -bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len); -int bufchain_fetch_consume_up_to(bufchain *ch, void *data, int len); +size_t bufchain_size(bufchain *ch); +void bufchain_add(bufchain *ch, const void *data, size_t len); +void bufchain_prefix(bufchain *ch, void **data, size_t *len); +void bufchain_consume(bufchain *ch, size_t len); +void bufchain_fetch(bufchain *ch, void *data, size_t len); +void bufchain_fetch_consume(bufchain *ch, void *data, size_t len); +bool bufchain_try_fetch_consume(bufchain *ch, void *data, size_t len); +size_t bufchain_fetch_consume_up_to(bufchain *ch, void *data, size_t len); void bufchain_set_callback_inner( bufchain *ch, IdempotentCallback *ic, void (*queue_idempotent_callback)(IdempotentCallback *ic)); @@ -125,7 +125,7 @@ static inline void bufchain_set_callback(bufchain *ch, IdempotentCallback *ic) bufchain_set_callback_inner(ch, ic, queue_idempotent_callback); } -void sanitise_term_data(bufchain *out, const void *vdata, int len); +void sanitise_term_data(bufchain *out, const void *vdata, size_t len); bool validate_manual_hostkey(char *key); diff --git a/network.h b/network.h index a84df7f0..740a09a2 100644 --- a/network.h +++ b/network.h @@ -28,8 +28,8 @@ struct SocketVtable { /* if p is NULL, it doesn't change the plug */ /* but it does return the one it's using */ void (*close) (Socket *s); - int (*write) (Socket *s, const void *data, int len); - int (*write_oob) (Socket *s, const void *data, int len); + size_t (*write) (Socket *s, const void *data, size_t len); + size_t (*write_oob) (Socket *s, const void *data, size_t len); void (*write_eof) (Socket *s); void (*flush) (Socket *s); void (*set_frozen) (Socket *s, bool is_frozen); @@ -70,7 +70,7 @@ struct PlugVtable { /* error_msg is NULL iff it is not an error (ie it closed normally) */ /* calling_back != 0 iff there is a Plug function */ /* currently running (would cure the fixme in try_send()) */ - void (*receive) (Plug *p, int urgent, const char *data, int len); + void (*receive) (Plug *p, int urgent, const char *data, size_t len); /* * - urgent==0. `data' points to `len' bytes of perfectly * ordinary data. @@ -81,7 +81,7 @@ struct PlugVtable { * - urgent==2. `data' points to `len' bytes of data, * the first of which was the one at the Urgent mark. */ - void (*sent) (Plug *p, int bufsize); + void (*sent) (Plug *p, size_t bufsize); /* * The `sent' function is called when the pending send backlog * on a socket is cleared or partially cleared. The new backlog @@ -279,6 +279,7 @@ void backend_socket_log(Seat *seat, LogContext *logctx, int type, SockAddr *addr, int port, const char *error_msg, int error_code, Conf *conf, bool session_started); -void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, int len); +void log_proxy_stderr( + Plug *plug, bufchain *buf, const void *vdata, size_t len); #endif diff --git a/nullplug.c b/nullplug.c index 25a3cc97..cbcd6a63 100644 --- a/nullplug.c +++ b/nullplug.c @@ -17,11 +17,12 @@ static void nullplug_closing(Plug *plug, const char *error_msg, int error_code, { } -static void nullplug_receive(Plug *plug, int urgent, const char *data, int len) +static void nullplug_receive( + Plug *plug, int urgent, const char *data, size_t len) { } -static void nullplug_sent(Plug *plug, int bufsize) +static void nullplug_sent(Plug *plug, size_t bufsize) { } diff --git a/pageant.c b/pageant.c index 216dc94d..baac3030 100644 --- a/pageant.c +++ b/pageant.c @@ -733,7 +733,7 @@ static void pageant_conn_closing(Plug *plug, const char *error_msg, sfree(pc); } -static void pageant_conn_sent(Plug *plug, int bufsize) +static void pageant_conn_sent(Plug *plug, size_t bufsize) { /* struct pageant_conn_state *pc = container_of( plug, struct pageant_conn_state, plug); */ @@ -756,7 +756,7 @@ static void pageant_conn_log(void *logctx, const char *fmt, va_list ap) } static void pageant_conn_receive( - Plug *plug, int urgent, const char *data, int len) + Plug *plug, int urgent, const char *data, size_t len) { struct pageant_conn_state *pc = container_of( plug, struct pageant_conn_state, plug); diff --git a/portfwd.c b/portfwd.c index 91d47802..6fd3d406 100644 --- a/portfwd.c +++ b/portfwd.c @@ -192,7 +192,7 @@ static char *ipv6_to_string(ptrlen ipv6) (unsigned)GET_16BIT_MSB_FIRST(addr + 14)); } -static void pfd_receive(Plug *plug, int urgent, const char *data, int len) +static void pfd_receive(Plug *plug, int urgent, const char *data, size_t len) { struct PortForwarding *pf = container_of(plug, struct PortForwarding, plug); @@ -417,7 +417,7 @@ static void pfd_receive(Plug *plug, int urgent, const char *data, int len) sshfwd_write(pf->c, data, len); } -static void pfd_sent(Plug *plug, int bufsize) +static void pfd_sent(Plug *plug, size_t bufsize) { struct PortForwarding *pf = container_of(plug, struct PortForwarding, plug); @@ -437,7 +437,8 @@ static const PlugVtable PortForwarding_plugvt = { static void pfd_chan_free(Channel *chan); static void pfd_open_confirmation(Channel *chan); static void pfd_open_failure(Channel *chan, const char *errtext); -static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len); +static size_t pfd_send( + Channel *chan, bool is_stderr, const void *data, size_t len); static void pfd_send_eof(Channel *chan); static void pfd_set_input_wanted(Channel *chan, bool wanted); static char *pfd_log_close_msg(Channel *chan); @@ -644,7 +645,8 @@ static void pfd_chan_free(Channel *chan) /* * Called to send data down the raw connection. */ -static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len) +static size_t pfd_send( + Channel *chan, bool is_stderr, const void *data, size_t len) { assert(chan->vt == &PortForwarding_channelvt); PortForwarding *pf = container_of(chan, PortForwarding, chan); diff --git a/proxy.c b/proxy.c index a83428da..9341c5f7 100644 --- a/proxy.c +++ b/proxy.c @@ -25,8 +25,7 @@ void proxy_activate (ProxySocket *p) { void *data; - int len; - long output_before, output_after; + size_t len, output_before, output_after; p->state = PROXY_STATE_ACTIVE; @@ -57,7 +56,7 @@ void proxy_activate (ProxySocket *p) /* if we managed to send any data, let the higher levels know. */ if (output_after < output_before) - plug_sent(p->plug, output_after); + plug_sent(p->plug, output_after); /* if we were asked to flush the output during * the proxy negotiation process, do so now. @@ -95,7 +94,7 @@ static void sk_proxy_close (Socket *s) sfree(ps); } -static int sk_proxy_write (Socket *s, const void *data, int len) +static size_t sk_proxy_write (Socket *s, const void *data, size_t len) { ProxySocket *ps = container_of(s, ProxySocket, sock); @@ -106,7 +105,7 @@ static int sk_proxy_write (Socket *s, const void *data, int len) return sk_write(ps->sub_socket, data, len); } -static int sk_proxy_write_oob (Socket *s, const void *data, int len) +static size_t sk_proxy_write_oob (Socket *s, const void *data, size_t len) { ProxySocket *ps = container_of(s, ProxySocket, sock); @@ -162,7 +161,7 @@ static void sk_proxy_set_frozen (Socket *s, bool is_frozen) while (!ps->freeze && bufchain_size(&ps->pending_input_data) > 0) { void *data; char databuf[512]; - int len; + size_t len; bufchain_prefix(&ps->pending_input_data, &data, &len); if (len > lenof(databuf)) len = lenof(databuf); @@ -214,7 +213,8 @@ static void plug_proxy_closing (Plug *p, const char *error_msg, } } -static void plug_proxy_receive (Plug *p, int urgent, const char *data, int len) +static void plug_proxy_receive( + Plug *p, int urgent, const char *data, size_t len) { ProxySocket *ps = container_of(p, ProxySocket, plugimpl); @@ -233,7 +233,7 @@ static void plug_proxy_receive (Plug *p, int urgent, const char *data, int len) } } -static void plug_proxy_sent (Plug *p, int bufsize) +static void plug_proxy_sent (Plug *p, size_t bufsize) { ProxySocket *ps = container_of(p, ProxySocket, plugimpl); @@ -544,9 +544,9 @@ Socket *new_listener(const char *srcaddr, int port, Plug *plug, * HTTP CONNECT proxy type. */ -static bool get_line_end(char *data, int len, int *out) +static bool get_line_end(char *data, size_t len, size_t *out) { - int off = 0; + size_t off = 0; while (off < len) { @@ -661,8 +661,7 @@ int proxy_http_negotiate (ProxySocket *p, int change) */ char *data, *datap; - int len; - int eol; + size_t len, eol; if (p->state == 1) { diff --git a/pscp.c b/pscp.c index 9e760c77..2abf901e 100644 --- a/pscp.c +++ b/pscp.c @@ -60,7 +60,7 @@ const char *const appname = "PSCP"; void ldisc_echoedit_update(Ldisc *ldisc) { } -static int pscp_output(Seat *, bool is_stderr, const void *, int); +static size_t pscp_output(Seat *, bool is_stderr, const void *, size_t); static bool pscp_eof(Seat *); static const SeatVtable pscp_seat_vt = { @@ -145,7 +145,8 @@ void agent_schedule_callback(void (*callback)(void *, void *, int), */ static bufchain received_data; -static int pscp_output(Seat *seat, bool is_stderr, const void *data, int len) +static size_t pscp_output( + Seat *seat, bool is_stderr, const void *data, size_t len) { /* * stderr data is just spouted to local stderr and otherwise @@ -175,7 +176,7 @@ static bool pscp_eof(Seat *seat) } return false; } -static bool ssh_scp_recv(void *vbuf, int len) +static bool ssh_scp_recv(void *vbuf, size_t len) { char *buf = (char *)vbuf; while (len > 0) { @@ -185,7 +186,7 @@ static bool ssh_scp_recv(void *vbuf, int len) return false; /* doom */ } - int got = bufchain_fetch_consume_up_to(&received_data, buf, len); + size_t got = bufchain_fetch_consume_up_to(&received_data, buf, len); buf += got; len -= got; } @@ -570,16 +571,16 @@ static int response(void) } } -bool sftp_recvdata(char *buf, int len) +bool sftp_recvdata(char *buf, size_t len) { return ssh_scp_recv(buf, len); } -bool sftp_senddata(const char *buf, int len) +bool sftp_senddata(const char *buf, size_t len) { backend_send(backend, buf, len); return true; } -int sftp_sendbuffer(void) +size_t sftp_sendbuffer(void) { return backend_sendbuffer(backend); } diff --git a/psftp.c b/psftp.c index 4a338da8..2e72ce07 100644 --- a/psftp.c +++ b/psftp.c @@ -41,7 +41,7 @@ bool sent_eof = false; * Seat vtable. */ -static int psftp_output(Seat *, bool is_stderr, const void *, int); +static size_t psftp_output(Seat *, bool is_stderr, const void *, size_t); static bool psftp_eof(Seat *); static const SeatVtable psftp_seat_vt = { @@ -2446,7 +2446,8 @@ void agent_schedule_callback(void (*callback)(void *, void *, int), */ static bufchain received_data; -static int psftp_output(Seat *seat, bool is_stderr, const void *data, int len) +static size_t psftp_output( + Seat *seat, bool is_stderr, const void *data, size_t len) { /* * stderr data is just spouted to local stderr and otherwise @@ -2477,7 +2478,7 @@ static bool psftp_eof(Seat *seat) return false; } -bool sftp_recvdata(char *buf, int len) +bool sftp_recvdata(char *buf, size_t len) { while (len > 0) { while (bufchain_size(&received_data) == 0) { @@ -2486,19 +2487,19 @@ bool sftp_recvdata(char *buf, int len) return false; /* doom */ } - int got = bufchain_fetch_consume_up_to(&received_data, buf, len); + size_t got = bufchain_fetch_consume_up_to(&received_data, buf, len); buf += got; len -= got; } return true; } -bool sftp_senddata(const char *buf, int len) +bool sftp_senddata(const char *buf, size_t len) { backend_send(backend, buf, len); return true; } -int sftp_sendbuffer(void) +size_t sftp_sendbuffer(void) { return backend_sendbuffer(backend); } diff --git a/putty.h b/putty.h index fe0e8a22..25f6e67e 100644 --- a/putty.h +++ b/putty.h @@ -503,9 +503,9 @@ struct BackendVtable { /* Pass in a replacement configuration. */ void (*reconfig) (Backend *be, Conf *conf); /* send() returns the current amount of buffered data. */ - int (*send) (Backend *be, const char *buf, int len); + size_t (*send) (Backend *be, const char *buf, size_t len); /* sendbuffer() does the same thing but without attempting a send */ - int (*sendbuffer) (Backend *be); + size_t (*sendbuffer) (Backend *be); void (*size) (Backend *be, int width, int height); void (*special) (Backend *be, SessionSpecialCode code, int arg); const SessionSpecial *(*get_specials) (Backend *be); @@ -518,7 +518,7 @@ struct BackendVtable { bool (*ldisc_option_state) (Backend *be, int); void (*provide_ldisc) (Backend *be, Ldisc *ldisc); /* Tells the back end that the front end buffer is clearing. */ - void (*unthrottle) (Backend *be, int bufsize); + void (*unthrottle) (Backend *be, size_t bufsize); int (*cfg_info) (Backend *be); /* Only implemented in the SSH protocol: check whether a @@ -742,7 +742,7 @@ struct SeatVtable { * * The return value is the current size of the output backlog. */ - int (*output)(Seat *seat, bool is_stderr, const void *data, int len); + size_t (*output)(Seat *seat, bool is_stderr, const void *data, size_t len); /* * Called when the back end wants to indicate that EOF has arrived @@ -964,7 +964,8 @@ void seat_connection_fatal(Seat *seat, const char *fmt, ...); * These are generally obvious, except for is_utf8, where you might * plausibly want to return either fixed answer 'no' or 'yes'. */ -int nullseat_output(Seat *seat, bool is_stderr, const void *data, int len); +size_t nullseat_output( + Seat *seat, bool is_stderr, const void *data, size_t len); bool nullseat_eof(Seat *seat); int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input); void nullseat_notify_remote_exit(Seat *seat); @@ -1546,7 +1547,7 @@ void term_reconfig(Terminal *, Conf *); void term_request_copy(Terminal *, const int *clipboards, int n_clipboards); void term_request_paste(Terminal *, int clipboard); void term_seen_key_event(Terminal *); -int term_data(Terminal *, bool is_stderr, const void *data, int len); +size_t term_data(Terminal *, bool is_stderr, const void *data, size_t len); void term_provide_backend(Terminal *term, Backend *backend); void term_provide_logctx(Terminal *term, LogContext *logctx); void term_set_focus(Terminal *term, bool has_focus); @@ -1634,7 +1635,7 @@ struct logblank_t { int type; }; void log_packet(LogContext *logctx, int direction, int type, - const char *texttype, const void *data, int len, + const char *texttype, const void *data, size_t len, int n_blanks, const struct logblank_t *blanks, const unsigned long *sequence, unsigned downstream_id, const char *additional_log_text); diff --git a/raw.c b/raw.c index d448e0e6..1db60e4f 100644 --- a/raw.c +++ b/raw.c @@ -14,7 +14,7 @@ typedef struct Raw Raw; struct Raw { Socket *s; bool closed_on_socket_error; - int bufsize; + size_t bufsize; Seat *seat; LogContext *logctx; bool sent_console_eof, sent_socket_eof, session_started; @@ -27,9 +27,9 @@ struct Raw { static void raw_size(Backend *be, int width, int height); -static void c_write(Raw *raw, const void *buf, int len) +static void c_write(Raw *raw, const void *buf, size_t len) { - int backlog = seat_stdout(raw->seat, buf, len); + size_t backlog = seat_stdout(raw->seat, buf, len); sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG); } @@ -89,7 +89,7 @@ static void raw_closing(Plug *plug, const char *error_msg, int error_code, } } -static void raw_receive(Plug *plug, int urgent, const char *data, int len) +static void raw_receive(Plug *plug, int urgent, const char *data, size_t len) { Raw *raw = container_of(plug, Raw, plug); c_write(raw, data, len); @@ -98,7 +98,7 @@ static void raw_receive(Plug *plug, int urgent, const char *data, int len) raw->session_started = true; } -static void raw_sent(Plug *plug, int bufsize) +static void raw_sent(Plug *plug, size_t bufsize) { Raw *raw = container_of(plug, Raw, plug); raw->bufsize = bufsize; @@ -201,7 +201,7 @@ static void raw_reconfig(Backend *be, Conf *conf) /* * Called to send data down the raw connection. */ -static int raw_send(Backend *be, const char *buf, int len) +static size_t raw_send(Backend *be, const char *buf, size_t len) { Raw *raw = container_of(be, Raw, backend); @@ -216,7 +216,7 @@ static int raw_send(Backend *be, const char *buf, int len) /* * Called to query the current socket sendability status. */ -static int raw_sendbuffer(Backend *be) +static size_t raw_sendbuffer(Backend *be) { Raw *raw = container_of(be, Raw, backend); return raw->bufsize; @@ -266,7 +266,7 @@ static bool raw_sendok(Backend *be) return true; } -static void raw_unthrottle(Backend *be, int backlog) +static void raw_unthrottle(Backend *be, size_t backlog) { Raw *raw = container_of(be, Raw, backend); sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG); diff --git a/rlogin.c b/rlogin.c index 27f2a0da..aac3fd11 100644 --- a/rlogin.c +++ b/rlogin.c @@ -31,9 +31,9 @@ struct Rlogin { Backend backend; }; -static void c_write(Rlogin *rlogin, const void *buf, int len) +static void c_write(Rlogin *rlogin, const void *buf, size_t len) { - int backlog = seat_stdout(rlogin->seat, buf, len); + size_t backlog = seat_stdout(rlogin->seat, buf, len); sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG); } @@ -71,7 +71,8 @@ static void rlogin_closing(Plug *plug, const char *error_msg, int error_code, } /* Otherwise, the remote side closed the connection normally. */ } -static void rlogin_receive(Plug *plug, int urgent, const char *data, int len) +static void rlogin_receive( + Plug *plug, int urgent, const char *data, size_t len) { Rlogin *rlogin = container_of(plug, Rlogin, plug); if (len == 0) @@ -110,7 +111,7 @@ static void rlogin_receive(Plug *plug, int urgent, const char *data, int len) } } -static void rlogin_sent(Plug *plug, int bufsize) +static void rlogin_sent(Plug *plug, size_t bufsize) { Rlogin *rlogin = container_of(plug, Rlogin, plug); rlogin->bufsize = bufsize; @@ -260,7 +261,7 @@ static void rlogin_reconfig(Backend *be, Conf *conf) /* * Called to send data down the rlogin connection. */ -static int rlogin_send(Backend *be, const char *buf, int len) +static size_t rlogin_send(Backend *be, const char *buf, size_t len) { Rlogin *rlogin = container_of(be, Rlogin, backend); bufchain bc; @@ -287,7 +288,7 @@ static int rlogin_send(Backend *be, const char *buf, int len) if (!rlogin->prompt) { while (bufchain_size(&bc) > 0) { void *data; - int len; + size_t len; bufchain_prefix(&bc, &data, &len); rlogin->bufsize = sk_write(rlogin->s, data, len); bufchain_consume(&bc, len); @@ -302,7 +303,7 @@ static int rlogin_send(Backend *be, const char *buf, int len) /* * Called to query the current socket sendability status. */ -static int rlogin_sendbuffer(Backend *be) +static size_t rlogin_sendbuffer(Backend *be) { Rlogin *rlogin = container_of(be, Rlogin, backend); return rlogin->bufsize; @@ -360,7 +361,7 @@ static bool rlogin_sendok(Backend *be) return true; } -static void rlogin_unthrottle(Backend *be, int backlog) +static void rlogin_unthrottle(Backend *be, size_t backlog) { Rlogin *rlogin = container_of(be, Rlogin, backend); sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG); diff --git a/scpserver.c b/scpserver.c index b61296cb..c082e091 100644 --- a/scpserver.c +++ b/scpserver.c @@ -481,7 +481,7 @@ static void scp_source_push_name( } static void scp_source_free(ScpServer *s); -static int scp_source_send(ScpServer *s, const void *data, size_t length); +static size_t scp_source_send(ScpServer *s, const void *data, size_t length); static void scp_source_eof(ScpServer *s); static void scp_source_throttle(ScpServer *s, bool throttled); @@ -859,7 +859,7 @@ static void scp_source_process_stack(ScpSource *scp) scp_requeue(scp); } -static int scp_source_send(ScpServer *s, const void *vdata, size_t length) +static size_t scp_source_send(ScpServer *s, const void *vdata, size_t length) { ScpSource *scp = container_of(s, ScpSource, scpserver); const char *data = (const char *)vdata; @@ -994,7 +994,7 @@ static void scp_sink_pop(ScpSink *scp) } static void scp_sink_free(ScpServer *s); -static int scp_sink_send(ScpServer *s, const void *data, size_t length); +static size_t scp_sink_send(ScpServer *s, const void *data, size_t length); static void scp_sink_eof(ScpServer *s); static void scp_sink_throttle(ScpServer *s, bool throttled) {} @@ -1078,7 +1078,7 @@ static void scp_sink_coroutine(ScpSink *scp) goto done; void *vdata; - int len; + size_t len; const char *cdata, *newline; bufchain_prefix(&scp->data, &vdata, &len); @@ -1180,7 +1180,7 @@ static void scp_sink_coroutine(ScpSink *scp) scp->file_offset = 0; while (scp->file_offset < scp->file_size) { void *vdata; - int len; + size_t len; uint64_t this_len, remaining; crMaybeWaitUntilV( @@ -1258,7 +1258,7 @@ static void scp_sink_coroutine(ScpSink *scp) crFinishV; } -static int scp_sink_send(ScpServer *s, const void *data, size_t length) +static size_t scp_sink_send(ScpServer *s, const void *data, size_t length) { ScpSink *scp = container_of(s, ScpSink, scpserver); @@ -1292,7 +1292,7 @@ struct ScpError { static void scp_error_free(ScpServer *s); -static int scp_error_send(ScpServer *s, const void *data, size_t length) +static size_t scp_error_send(ScpServer *s, const void *data, size_t length) { return 0; } static void scp_error_eof(ScpServer *s) {} static void scp_error_throttle(ScpServer *s, bool throttled) {} diff --git a/sesschan.c b/sesschan.c index 14eee41e..4b98857b 100644 --- a/sesschan.c +++ b/sesschan.c @@ -48,7 +48,8 @@ typedef struct sesschan { } sesschan; static void sesschan_free(Channel *chan); -static int sesschan_send(Channel *chan, bool is_stderr, const void *, int); +static size_t sesschan_send( + Channel *chan, bool is_stderr, const void *, size_t); static void sesschan_send_eof(Channel *chan); static char *sesschan_log_close_msg(Channel *chan); static bool sesschan_want_close(Channel *, bool, bool); @@ -95,7 +96,8 @@ static const struct ChannelVtable sesschan_channelvt = { chan_no_request_response, }; -static int sftp_chan_send(Channel *chan, bool is_stderr, const void *, int); +static size_t sftp_chan_send( + Channel *chan, bool is_stderr, const void *, size_t); static void sftp_chan_send_eof(Channel *chan); static char *sftp_log_close_msg(Channel *chan); @@ -124,7 +126,8 @@ static const struct ChannelVtable sftp_channelvt = { chan_no_request_response, }; -static int scp_chan_send(Channel *chan, bool is_stderr, const void *, int); +static size_t scp_chan_send( + Channel *chan, bool is_stderr, const void *, size_t); static void scp_chan_send_eof(Channel *chan); static void scp_set_input_wanted(Channel *chan, bool wanted); static char *scp_log_close_msg(Channel *chan); @@ -166,7 +169,8 @@ static const LogPolicyVtable sesschan_logpolicy_vt = { sesschan_logging_error, }; -static int sesschan_seat_output(Seat *, bool is_stderr, const void *, int); +static size_t sesschan_seat_output( + Seat *, bool is_stderr, const void *, size_t); static bool sesschan_seat_eof(Seat *); static void sesschan_notify_remote_exit(Seat *seat); static void sesschan_connection_fatal(Seat *seat, const char *message); @@ -241,8 +245,8 @@ static void sesschan_free(Channel *chan) sfree(sess); } -static int sesschan_send(Channel *chan, bool is_stderr, - const void *data, int length) +static size_t sesschan_send(Channel *chan, bool is_stderr, + const void *data, size_t length) { sesschan *sess = container_of(chan, sesschan, chan); @@ -553,8 +557,8 @@ bool sesschan_change_window_size( return true; } -static int sesschan_seat_output( - Seat *seat, bool is_stderr, const void *data, int len) +static size_t sesschan_seat_output( + Seat *seat, bool is_stderr, const void *data, size_t len) { sesschan *sess = container_of(seat, sesschan, seat); return sshfwd_write_ext(sess->c, is_stderr, data, len); @@ -647,8 +651,8 @@ static bool sesschan_get_window_pixel_size(Seat *seat, int *width, int *height) * Built-in SFTP subsystem. */ -static int sftp_chan_send(Channel *chan, bool is_stderr, - const void *data, int length) +static size_t sftp_chan_send(Channel *chan, bool is_stderr, + const void *data, size_t length) { sesschan *sess = container_of(chan, sesschan, chan); @@ -695,8 +699,8 @@ static char *sftp_log_close_msg(Channel *chan) * Built-in SCP subsystem. */ -static int scp_chan_send(Channel *chan, bool is_stderr, - const void *data, int length) +static size_t scp_chan_send(Channel *chan, bool is_stderr, + const void *data, size_t length) { sesschan *sess = container_of(chan, sesschan, chan); return scp_send(sess->scpsrv, data, length); diff --git a/sftp.h b/sftp.h index cdbea3e5..abaea47e 100644 --- a/sftp.h +++ b/sftp.h @@ -70,9 +70,9 @@ * sftp_sendbuffer returns the size of the backlog of data in the * transmit queue. */ -bool sftp_senddata(const char *data, int len); -int sftp_sendbuffer(void); -bool sftp_recvdata(char *data, int len); +bool sftp_senddata(const char *data, size_t len); +size_t sftp_sendbuffer(void); +bool sftp_recvdata(char *data, size_t len); /* * Free sftp_requests @@ -494,7 +494,7 @@ struct ScpServer { struct ScpServerVtable { void (*free)(ScpServer *s); - int (*send)(ScpServer *s, const void *data, size_t length); + size_t (*send)(ScpServer *s, const void *data, size_t length); void (*throttle)(ScpServer *s, bool throttled); void (*eof)(ScpServer *s); }; diff --git a/ssh.c b/ssh.c index eabd3361..8bf6cb77 100644 --- a/ssh.c +++ b/ssh.c @@ -61,7 +61,7 @@ struct Ssh { int version; int conn_throttle_count; - int overall_bufsize; + size_t overall_bufsize; bool throttled_all; /* @@ -139,7 +139,7 @@ struct Ssh { logevent_and_free((ssh)->logctx, dupprintf params)) static void ssh_shutdown(Ssh *ssh); -static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize); +static void ssh_throttle_all(Ssh *ssh, bool enable, size_t bufsize); static void ssh_bpp_output_raw_data_callback(void *vctx); LogContext *ssh_get_logctx(Ssh *ssh) @@ -349,7 +349,7 @@ static void ssh_bpp_output_raw_data_callback(void *vctx) while (bufchain_size(&ssh->out_raw) > 0) { void *data; - int len, backlog; + size_t len, backlog; bufchain_prefix(&ssh->out_raw, &data, &len); @@ -573,7 +573,7 @@ static void ssh_closing(Plug *plug, const char *error_msg, int error_code, } } -static void ssh_receive(Plug *plug, int urgent, const char *data, int len) +static void ssh_receive(Plug *plug, int urgent, const char *data, size_t len) { Ssh *ssh = container_of(plug, Ssh, plug); @@ -589,7 +589,7 @@ static void ssh_receive(Plug *plug, int urgent, const char *data, int len) ssh_check_frozen(ssh); } -static void ssh_sent(Plug *plug, int bufsize) +static void ssh_sent(Plug *plug, size_t bufsize) { Ssh *ssh = container_of(plug, Ssh, plug); /* @@ -810,7 +810,7 @@ void ssh_throttle_conn(Ssh *ssh, int adjust) * Throttle or unthrottle _all_ local data streams (for when sends * on the SSH connection itself back up). */ -static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize) +static void ssh_throttle_all(Ssh *ssh, bool enable, size_t bufsize) { if (enable == ssh->throttled_all) return; @@ -928,7 +928,7 @@ static void ssh_reconfig(Backend *be, Conf *conf) /* * Called to send data down the SSH connection. */ -static int ssh_send(Backend *be, const char *buf, int len) +static size_t ssh_send(Backend *be, const char *buf, size_t len) { Ssh *ssh = container_of(be, Ssh, backend); @@ -945,10 +945,10 @@ static int ssh_send(Backend *be, const char *buf, int len) /* * Called to query the current amount of buffered stdin data. */ -static int ssh_sendbuffer(Backend *be) +static size_t ssh_sendbuffer(Backend *be) { Ssh *ssh = container_of(be, Ssh, backend); - int backlog; + size_t backlog; if (!ssh || !ssh->s || !ssh->cl) return 0; @@ -1049,7 +1049,7 @@ static void ssh_special(Backend *be, SessionSpecialCode code, int arg) * This is called when the seat's output channel manages to clear some * backlog. */ -static void ssh_unthrottle(Backend *be, int bufsize) +static void ssh_unthrottle(Backend *be, size_t bufsize) { Ssh *ssh = container_of(be, Ssh, backend); diff --git a/ssh.h b/ssh.h index 309bde4d..e90162e3 100644 --- a/ssh.h +++ b/ssh.h @@ -271,10 +271,10 @@ struct ConnectionLayerVtable { void (*terminal_size)(ConnectionLayer *cl, int width, int height); /* Indicate that the backlog on standard output has cleared */ - void (*stdout_unthrottle)(ConnectionLayer *cl, int bufsize); + void (*stdout_unthrottle)(ConnectionLayer *cl, size_t bufsize); /* Query the size of the backlog on standard _input_ */ - int (*stdin_backlog)(ConnectionLayer *cl); + size_t (*stdin_backlog)(ConnectionLayer *cl); /* Tell the connection layer that the SSH connection itself has * backed up, so it should tell all currently open channels to diff --git a/ssh1connection-client.c b/ssh1connection-client.c index 8c46483d..faa0df28 100644 --- a/ssh1connection-client.c +++ b/ssh1connection-client.c @@ -396,8 +396,8 @@ static void ssh1mainchan_hint_channel_is_simple(SshChannel *sc) { } -static int ssh1mainchan_write( - SshChannel *sc, bool is_stderr, const void *data, int len) +static size_t ssh1mainchan_write( + SshChannel *sc, bool is_stderr, const void *data, size_t len) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); diff --git a/ssh1connection-server.c b/ssh1connection-server.c index c2975325..14a54ae7 100644 --- a/ssh1connection-server.c +++ b/ssh1connection-server.c @@ -13,8 +13,8 @@ #include "ssh1connection.h" #include "sshserver.h" -static int ssh1sesschan_write(SshChannel *c, bool is_stderr, - const void *, int); +static size_t ssh1sesschan_write(SshChannel *c, bool is_stderr, + const void *, size_t); static void ssh1sesschan_write_eof(SshChannel *c); static void ssh1sesschan_initiate_close(SshChannel *c, const char *err); static void ssh1sesschan_send_exit_status(SshChannel *c, int status); @@ -274,8 +274,8 @@ struct ssh_rportfwd *ssh1_rportfwd_alloc( unreachable("Should never be called in the server"); } -static int ssh1sesschan_write(SshChannel *sc, bool is_stderr, - const void *data, int len) +static size_t ssh1sesschan_write(SshChannel *sc, bool is_stderr, + const void *data, size_t len) { struct ssh1_connection_state *s = container_of(sc, struct ssh1_connection_state, mainchan_sc); diff --git a/ssh1connection.c b/ssh1connection.c index fb3fe93f..78cd1425 100644 --- a/ssh1connection.c +++ b/ssh1connection.c @@ -55,8 +55,8 @@ static struct X11FakeAuth *ssh1_add_x11_display( ConnectionLayer *cl, int authtype, struct X11Display *disp); static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl); static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height); -static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize); -static int ssh1_stdin_backlog(ConnectionLayer *cl); +static void ssh1_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize); +static size_t ssh1_stdin_backlog(ConnectionLayer *cl); static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled); static bool ssh1_ldisc_option(ConnectionLayer *cl, int option); static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value); @@ -91,11 +91,11 @@ static const struct ConnectionLayerVtable ssh1_connlayer_vtable = { ssh1_set_wants_user_input, }; -static int ssh1channel_write( - SshChannel *c, bool is_stderr, const void *buf, int len); +static size_t ssh1channel_write( + SshChannel *c, bool is_stderr, const void *buf, size_t len); static void ssh1channel_write_eof(SshChannel *c); static void ssh1channel_initiate_close(SshChannel *c, const char *err); -static void ssh1channel_unthrottle(SshChannel *c, int bufsize); +static void ssh1channel_unthrottle(SshChannel *c, size_t bufsize); static Conf *ssh1channel_get_conf(SshChannel *c); static void ssh1channel_window_override_removed(SshChannel *c) { /* ignore */ } @@ -578,7 +578,7 @@ static void ssh1channel_initiate_close(SshChannel *sc, const char *err) ssh1_channel_check_close(c); } -static void ssh1channel_unthrottle(SshChannel *sc, int bufsize) +static void ssh1channel_unthrottle(SshChannel *sc, size_t bufsize) { struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); struct ssh1_connection_state *s = c->connlayer; @@ -589,8 +589,8 @@ static void ssh1channel_unthrottle(SshChannel *sc, int bufsize) } } -static int ssh1channel_write( - SshChannel *sc, bool is_stderr, const void *buf, int len) +static size_t ssh1channel_write( + SshChannel *sc, bool is_stderr, const void *buf, size_t len) { struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc); struct ssh1_connection_state *s = c->connlayer; @@ -695,7 +695,7 @@ static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height) mainchan_terminal_size(s->mainchan, width, height); } -static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize) +static void ssh1_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize) { struct ssh1_connection_state *s = container_of(cl, struct ssh1_connection_state, cl); @@ -706,7 +706,7 @@ static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize) } } -static int ssh1_stdin_backlog(ConnectionLayer *cl) +static size_t ssh1_stdin_backlog(ConnectionLayer *cl) { return 0; } @@ -781,7 +781,7 @@ static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl) * Add user input to the main channel's buffer. */ void *data; - int len; + size_t len; bufchain_prefix(s->ppl.user_input, &data, &len); if (len > 512) len = 512; diff --git a/ssh2connection.c b/ssh2connection.c index fff5bdcd..da573ee3 100644 --- a/ssh2connection.c +++ b/ssh2connection.c @@ -55,8 +55,8 @@ static void ssh2_sharing_queue_global_request( static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl); static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl); static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height); -static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize); -static int ssh2_stdin_backlog(ConnectionLayer *cl); +static void ssh2_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize); +static size_t ssh2_stdin_backlog(ConnectionLayer *cl); static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled); static bool ssh2_ldisc_option(ConnectionLayer *cl, int option); static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value); @@ -118,11 +118,11 @@ static char *ssh2_channel_open_failure_error_text(PktIn *pktin) return dupprintf("%s [%.*s]", reason_code_string, PTRLEN_PRINTF(reason)); } -static int ssh2channel_write( - SshChannel *c, bool is_stderr, const void *buf, int len); +static size_t ssh2channel_write( + SshChannel *c, bool is_stderr, const void *buf, size_t len); static void ssh2channel_write_eof(SshChannel *c); static void ssh2channel_initiate_close(SshChannel *c, const char *err); -static void ssh2channel_unthrottle(SshChannel *c, int bufsize); +static void ssh2channel_unthrottle(SshChannel *c, size_t bufsize); static Conf *ssh2channel_get_conf(SshChannel *c); static void ssh2channel_window_override_removed(SshChannel *c); static void ssh2channel_x11_sharing_handover( @@ -158,7 +158,7 @@ static const struct SshChannelVtable ssh2channel_vtable = { static void ssh2_channel_check_close(struct ssh2_channel *c); static void ssh2_channel_try_eof(struct ssh2_channel *c); static void ssh2_set_window(struct ssh2_channel *c, int newwin); -static int ssh2_try_send(struct ssh2_channel *c); +static size_t ssh2_try_send(struct ssh2_channel *c); static void ssh2_try_send_and_unthrottle(struct ssh2_channel *c); static void ssh2_channel_check_throttle(struct ssh2_channel *c); static void ssh2_channel_close_local(struct ssh2_channel *c, @@ -1055,24 +1055,24 @@ static void ssh2_channel_try_eof(struct ssh2_channel *c) /* * Attempt to send data on an SSH-2 channel. */ -static int ssh2_try_send(struct ssh2_channel *c) +static size_t ssh2_try_send(struct ssh2_channel *c) { struct ssh2_connection_state *s = c->connlayer; PktOut *pktout; - int bufsize; + size_t bufsize; while (c->remwindow > 0 && (bufchain_size(&c->outbuffer) > 0 || bufchain_size(&c->errbuffer) > 0)) { - int len; + size_t len; void *data; bufchain *buf = (bufchain_size(&c->errbuffer) > 0 ? &c->errbuffer : &c->outbuffer); bufchain_prefix(buf, &data, &len); - if ((unsigned)len > c->remwindow) + if (len > c->remwindow) len = c->remwindow; - if ((unsigned)len > c->remmaxpkt) + if (len > c->remmaxpkt) len = c->remmaxpkt; if (buf == &c->errbuffer) { pktout = ssh_bpp_new_pktout( @@ -1322,11 +1322,11 @@ static void ssh2channel_initiate_close(SshChannel *sc, const char *err) ssh2_channel_check_close(c); } -static void ssh2channel_unthrottle(SshChannel *sc, int bufsize) +static void ssh2channel_unthrottle(SshChannel *sc, size_t bufsize) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); struct ssh2_connection_state *s = c->connlayer; - int buflimit; + size_t buflimit; buflimit = s->ssh_is_simple ? 0 : c->locmaxwin; if (bufsize < buflimit) @@ -1338,8 +1338,8 @@ static void ssh2channel_unthrottle(SshChannel *sc, int bufsize) } } -static int ssh2channel_write( - SshChannel *sc, bool is_stderr, const void *buf, int len) +static size_t ssh2channel_write( + SshChannel *sc, bool is_stderr, const void *buf, size_t len) { struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc); assert(!(c->closes & CLOSES_SENT_EOF)); @@ -1578,7 +1578,7 @@ static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height) mainchan_terminal_size(s->mainchan, width, height); } -static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize) +static void ssh2_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize) { struct ssh2_connection_state *s = container_of(cl, struct ssh2_connection_state, cl); @@ -1587,7 +1587,7 @@ static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize) sshfwd_unthrottle(s->mainchan_sc, bufsize); } -static int ssh2_stdin_backlog(ConnectionLayer *cl) +static size_t ssh2_stdin_backlog(ConnectionLayer *cl) { struct ssh2_connection_state *s = container_of(cl, struct ssh2_connection_state, cl); @@ -1671,7 +1671,7 @@ static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl) * Add user input to the main channel's buffer. */ void *data; - int len; + size_t len; bufchain_prefix(s->ppl.user_input, &data, &len); sshfwd_write(s->mainchan_sc, data, len); bufchain_consume(s->ppl.user_input, len); diff --git a/ssh2userauth.c b/ssh2userauth.c index 46fb3d37..7acdaa0c 100644 --- a/ssh2userauth.c +++ b/ssh2userauth.c @@ -466,7 +466,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) (flags & (FLAG_VERBOSE | FLAG_INTERACTIVE))) { while (bufchain_size(&s->banner) > 0) { void *data; - int len; + size_t len; bufchain_prefix(&s->banner, &data, &len); seat_stderr(s->ppl.seat, data, len); bufchain_consume(&s->banner, len); diff --git a/sshchan.h b/sshchan.h index 9ec256d6..367cc2ef 100644 --- a/sshchan.h +++ b/sshchan.h @@ -19,7 +19,7 @@ struct ChannelVtable { void (*open_confirmation)(Channel *); void (*open_failed)(Channel *, const char *error_text); - int (*send)(Channel *, bool is_stderr, const void *buf, int len); + size_t (*send)(Channel *, bool is_stderr, const void *buf, size_t len); void (*send_eof)(Channel *); void (*set_input_wanted)(Channel *, bool wanted); @@ -156,10 +156,10 @@ Channel *zombiechan_new(void); */ struct SshChannelVtable { - int (*write)(SshChannel *c, bool is_stderr, const void *, int); + size_t (*write)(SshChannel *c, bool is_stderr, const void *, size_t); void (*write_eof)(SshChannel *c); void (*initiate_close)(SshChannel *c, const char *err); - void (*unthrottle)(SshChannel *c, int bufsize); + void (*unthrottle)(SshChannel *c, size_t bufsize); Conf *(*get_conf)(SshChannel *c); void (*window_override_removed)(SshChannel *c); void (*x11_sharing_handover)(SshChannel *c, diff --git a/sshcommon.c b/sshcommon.c index 7d23775d..65cce855 100644 --- a/sshcommon.c +++ b/sshcommon.c @@ -262,7 +262,8 @@ void ssh_free_pktout(PktOut *pkt) */ static void zombiechan_free(Channel *chan); -static int zombiechan_send(Channel *chan, bool is_stderr, const void *, int); +static size_t zombiechan_send( + Channel *chan, bool is_stderr, const void *, size_t); static void zombiechan_set_input_wanted(Channel *chan, bool wanted); static void zombiechan_do_nothing(Channel *chan); static void zombiechan_open_failure(Channel *chan, const char *); @@ -318,8 +319,8 @@ static void zombiechan_open_failure(Channel *chan, const char *errtext) assert(chan->vt == &zombiechan_channelvt); } -static int zombiechan_send(Channel *chan, bool is_stderr, - const void *data, int length) +static size_t zombiechan_send(Channel *chan, bool is_stderr, + const void *data, size_t length) { assert(chan->vt == &zombiechan_channelvt); return 0; diff --git a/sshserver.c b/sshserver.c index d89e3809..334ef1e2 100644 --- a/sshserver.c +++ b/sshserver.c @@ -133,7 +133,8 @@ static void server_closing(Plug *plug, const char *error_msg, int error_code, } } -static void server_receive(Plug *plug, int urgent, const char *data, int len) +static void server_receive( + Plug *plug, int urgent, const char *data, size_t len) { server *srv = container_of(plug, server, plug); @@ -147,7 +148,7 @@ static void server_receive(Plug *plug, int urgent, const char *data, int len) queue_idempotent_callback(&srv->bpp->ic_in_raw); } -static void server_sent(Plug *plug, int bufsize) +static void server_sent(Plug *plug, size_t bufsize) { #ifdef FIXME server *srv = container_of(plug, server, plug); @@ -333,7 +334,7 @@ static void server_bpp_output_raw_data_callback(void *vctx) while (bufchain_size(&srv->out_raw) > 0) { void *data; - int len, backlog; + size_t len, backlog; bufchain_prefix(&srv->out_raw, &data, &len); diff --git a/sshshare.c b/sshshare.c index 89b57536..04301656 100644 --- a/sshshare.c +++ b/sshshare.c @@ -164,7 +164,7 @@ struct ssh_sharing_connstate { int curr_packetlen; unsigned char recvbuf[0x4010]; - int recvlen; + size_t recvlen; /* * Assorted state we have to remember about this downstream, so @@ -1754,7 +1754,7 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs, (c) = (unsigned char)*data++; \ } while (0) -static void share_receive(Plug *plug, int urgent, const char *data, int len) +static void share_receive(Plug *plug, int urgent, const char *data, size_t len) { ssh_sharing_connstate *cs = container_of( plug, ssh_sharing_connstate, plug); @@ -1830,7 +1830,7 @@ static void share_receive(Plug *plug, int urgent, const char *data, int len) crFinishV; } -static void share_sent(Plug *plug, int bufsize) +static void share_sent(Plug *plug, size_t bufsize) { /* ssh_sharing_connstate *cs = container_of( plug, ssh_sharing_connstate, plug); */ diff --git a/sshverstring.c b/sshverstring.c index d1641e7c..dff350ac 100644 --- a/sshverstring.c +++ b/sshverstring.c @@ -29,7 +29,7 @@ struct ssh_verstring_state { char prefix[PREFIX_MAXLEN]; char *impl_name; char *vstring; - int vslen, vstrsize; + size_t vslen, vstrsize; char *protoversion; const char *softwareversion; @@ -249,7 +249,7 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp) * If we didn't find it, consume data until we see a newline. */ while (1) { - int len; + size_t len; void *data; char *nl; @@ -281,7 +281,7 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp) */ s->i = 0; do { - int len; + size_t len; void *data; char *nl; @@ -291,7 +291,7 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp) len = nl - (char *)data + 1; } - if (s->vslen + len >= s->vstrsize - 1) { + if (s->vslen >= s->vstrsize - 1 || len >= s->vstrsize - 1 - s->vslen) { s->vstrsize = (s->vslen + len) * 5 / 4 + 32; s->vstring = sresize(s->vstring, s->vstrsize, char); } diff --git a/telnet.c b/telnet.c index 8fb0f572..8199c7d9 100644 --- a/telnet.c +++ b/telnet.c @@ -182,7 +182,7 @@ struct Telnet { bool echoing, editing; bool activated; - int bufsize; + size_t bufsize; bool in_synch; int sb_opt, sb_len; unsigned char *sb_buf; @@ -206,10 +206,9 @@ struct Telnet { #define SB_DELTA 1024 -static void c_write(Telnet *telnet, const void *buf, int len) +static void c_write(Telnet *telnet, const void *buf, size_t len) { - int backlog; - backlog = seat_stdout(telnet->seat, buf, len); + size_t backlog = seat_stdout(telnet->seat, buf, len); sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG); } @@ -506,7 +505,7 @@ static void process_subneg(Telnet *telnet) } } -static void do_telnet_read(Telnet *telnet, const char *buf, int len) +static void do_telnet_read(Telnet *telnet, const char *buf, size_t len) { strbuf *outbuf = strbuf_new(); @@ -654,7 +653,8 @@ static void telnet_closing(Plug *plug, const char *error_msg, int error_code, /* Otherwise, the remote side closed the connection normally. */ } -static void telnet_receive(Plug *plug, int urgent, const char *data, int len) +static void telnet_receive( + Plug *plug, int urgent, const char *data, size_t len) { Telnet *telnet = container_of(plug, Telnet, plug); if (urgent) @@ -663,7 +663,7 @@ static void telnet_receive(Plug *plug, int urgent, const char *data, int len) do_telnet_read(telnet, data, len); } -static void telnet_sent(Plug *plug, int bufsize) +static void telnet_sent(Plug *plug, size_t bufsize) { Telnet *telnet = container_of(plug, Telnet, plug); telnet->bufsize = bufsize; @@ -815,7 +815,7 @@ static void telnet_reconfig(Backend *be, Conf *conf) /* * Called to send data down the Telnet connection. */ -static int telnet_send(Backend *be, const char *buf, int len) +static size_t telnet_send(Backend *be, const char *buf, size_t len) { Telnet *telnet = container_of(be, Telnet, backend); unsigned char *p, *end; @@ -850,7 +850,7 @@ static int telnet_send(Backend *be, const char *buf, int len) /* * Called to query the current socket sendability status. */ -static int telnet_sendbuffer(Backend *be) +static size_t telnet_sendbuffer(Backend *be) { Telnet *telnet = container_of(be, Telnet, backend); return telnet->bufsize; @@ -1009,7 +1009,7 @@ static bool telnet_sendok(Backend *be) return true; } -static void telnet_unthrottle(Backend *be, int backlog) +static void telnet_unthrottle(Backend *be, size_t backlog) { Telnet *telnet = container_of(be, Telnet, backend); sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG); diff --git a/terminal.c b/terminal.c index 6f4b15ae..7f5fe7f1 100644 --- a/terminal.c +++ b/terminal.c @@ -2692,8 +2692,7 @@ static void term_print_setup(Terminal *term, char *printer) static void term_print_flush(Terminal *term) { void *data; - int len; - int size; + size_t len, size; while ((size = bufchain_size(&term->printer_buf)) > 5) { bufchain_prefix(&term->printer_buf, &data, &len); if (len > size-5) @@ -2705,7 +2704,7 @@ static void term_print_flush(Terminal *term) static void term_print_finish(Terminal *term) { void *data; - int len, size; + size_t len, size; char c; if (!term->printing && !term->only_printing) @@ -2875,7 +2874,7 @@ static void term_out(Terminal *term) unsigned long c; int unget; unsigned char localbuf[256], *chars; - int nchars = 0; + size_t nchars = 0; unget = -1; @@ -6713,7 +6712,7 @@ static void term_added_data(Terminal *term) } } -int term_data(Terminal *term, bool is_stderr, const void *data, int len) +size_t term_data(Terminal *term, bool is_stderr, const void *data, size_t len) { bufchain_add(&term->inbuf, data, len); term_added_data(term); @@ -6740,7 +6739,7 @@ int term_data(Terminal *term, bool is_stderr, const void *data, int len) return 0; } -static void term_data_untrusted(Terminal *term, const void *data, int len) +static void term_data_untrusted(Terminal *term, const void *data, size_t len) { sanitise_term_data(&term->inbuf, data, len); term_added_data(term); diff --git a/testback.c b/testback.c index b54c682e..1a71d025 100644 --- a/testback.c +++ b/testback.c @@ -39,9 +39,9 @@ static const char *loop_init(Seat *, Backend **, LogContext *, Conf *, static void null_free(Backend *); static void loop_free(Backend *); static void null_reconfig(Backend *, Conf *); -static int null_send(Backend *, const char *, int); -static int loop_send(Backend *, const char *, int); -static int null_sendbuffer(Backend *); +static size_t null_send(Backend *, const char *, size_t); +static size_t loop_send(Backend *, const char *, size_t); +static size_t null_sendbuffer(Backend *); static void null_size(Backend *, int, int); static void null_special(Backend *, SessionSpecialCode, int); static const SessionSpecial *null_get_specials(Backend *); @@ -50,7 +50,7 @@ static int null_exitcode(Backend *); static int null_sendok(Backend *); static int null_ldisc(Backend *, int); static void null_provide_ldisc(Backend *, Ldisc *); -static void null_unthrottle(Backend *, int); +static void null_unthrottle(Backend *, size_t); static int null_cfg_info(Backend *); const struct BackendVtable null_backend = { @@ -107,18 +107,18 @@ static void null_reconfig(Backend *be, Conf *conf) { } -static int null_send(Backend *be, const char *buf, int len) { +static size_t null_send(Backend *be, const char *buf, size_t len) { return 0; } -static int loop_send(Backend *be, const char *buf, int len) { +static size_t loop_send(Backend *be, const char *buf, size_t len) { struct loop_state *st = container_of(be, struct loop_state, backend); return seat_output(st->seat, 0, buf, len); } -static int null_sendbuffer(Backend *be) { +static size_t null_sendbuffer(Backend *be) { return 0; } @@ -151,7 +151,7 @@ static int null_sendok(Backend *be) { return 1; } -static void null_unthrottle(Backend *be, int backlog) { +static void null_unthrottle(Backend *be, size_t backlog) { } diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 1f7f2dcc..162e1f48 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -314,8 +314,8 @@ static char *gtk_seat_get_ttymode(Seat *seat, const char *mode) return term_get_ttymode(inst->term, mode); } -static int gtk_seat_output(Seat *seat, bool is_stderr, - const void *data, int len) +static size_t gtk_seat_output(Seat *seat, bool is_stderr, + const void *data, size_t len) { GtkFrontend *inst = container_of(seat, GtkFrontend, seat); return term_data(inst->term, is_stderr, data, len); diff --git a/unix/uxcons.c b/unix/uxcons.c index 1b5aabb3..05ae8bf3 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -490,7 +490,7 @@ static void console_close(FILE *outfp, int infd) fclose(outfp); /* will automatically close infd too */ } -static void console_prompt_text(FILE *outfp, const char *data, int len) +static void console_prompt_text(FILE *outfp, const char *data, size_t len) { bufchain sanitised; void *vdata; diff --git a/unix/uxfdsock.c b/unix/uxfdsock.c index 06a5060f..099c9c00 100644 --- a/unix/uxfdsock.c +++ b/unix/uxfdsock.c @@ -163,7 +163,8 @@ static int fdsocket_try_send(FdSocket *fds) while (bufchain_size(&fds->pending_output_data) > 0) { void *data; - int len, ret; + size_t len; + ssize_t ret; bufchain_prefix(&fds->pending_output_data, &data, &len); ret = write(fds->outfd, data, len); @@ -198,7 +199,7 @@ static int fdsocket_try_send(FdSocket *fds) return sent; } -static int fdsocket_write(Socket *s, const void *data, int len) +static size_t fdsocket_write(Socket *s, const void *data, size_t len) { FdSocket *fds = container_of(s, FdSocket, sock); @@ -211,7 +212,7 @@ static int fdsocket_write(Socket *s, const void *data, int len) return bufchain_size(&fds->pending_output_data); } -static int fdsocket_write_oob(Socket *s, const void *data, int len) +static size_t fdsocket_write_oob(Socket *s, const void *data, size_t len) { /* * oob data is treated as inband; nasty, but nothing really diff --git a/unix/uxnet.c b/unix/uxnet.c index 0dbb0ca5..68e21a7d 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -69,7 +69,7 @@ struct NetSocket { bool frozen; /* this causes readability notifications to be ignored */ bool localhost_only; /* for listening sockets */ char oobdata[1]; - int sending_oob; + size_t sending_oob; bool oobpending; /* is there OOB data available to read? */ bool oobinline; enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; @@ -500,8 +500,8 @@ static void sk_net_flush(Socket *s) } static void sk_net_close(Socket *s); -static int sk_net_write(Socket *s, const void *data, int len); -static int sk_net_write_oob(Socket *s, const void *data, int len); +static size_t sk_net_write(Socket *s, const void *data, size_t len); +static size_t sk_net_write_oob(Socket *s, const void *data, size_t len); static void sk_net_write_eof(Socket *s); static void sk_net_set_frozen(Socket *s, bool is_frozen); static SocketPeerInfo *sk_net_peer_info(Socket *s); @@ -1112,7 +1112,8 @@ void try_send(NetSocket *s) int nsent; int err; void *data; - int len, urgentflag; + size_t len; + int urgentflag; if (s->sending_oob) { urgentflag = MSG_OOB; @@ -1186,7 +1187,7 @@ void try_send(NetSocket *s) uxsel_tell(s); } -static int sk_net_write(Socket *sock, const void *buf, int len) +static size_t sk_net_write(Socket *sock, const void *buf, size_t len) { NetSocket *s = container_of(sock, NetSocket, sock); @@ -1212,7 +1213,7 @@ static int sk_net_write(Socket *sock, const void *buf, int len) return bufchain_size(&s->output_data); } -static int sk_net_write_oob(Socket *sock, const void *buf, int len) +static size_t sk_net_write_oob(Socket *sock, const void *buf, size_t len) { NetSocket *s = container_of(sock, NetSocket, sock); @@ -1451,7 +1452,7 @@ static void net_select_result(int fd, int event) s->writable = true; uxsel_tell(s); } else { - int bufsize_before, bufsize_after; + size_t bufsize_before, bufsize_after; s->writable = true; bufsize_before = s->sending_oob + bufchain_size(&s->output_data); try_send(s); diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 193a7dee..706345d1 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -155,8 +155,8 @@ void chan_no_request_response(Channel *chan, bool success) {} */ static void x11_log(Plug *p, int type, SockAddr *addr, int port, const char *error_msg, int error_code) {} -static void x11_receive(Plug *plug, int urgent, const char *data, int len) {} -static void x11_sent(Plug *plug, int bufsize) {} +static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) {} +static void x11_sent(Plug *plug, size_t bufsize) {} static void x11_closing(Plug *plug, const char *error_msg, int error_code, bool calling_back) { diff --git a/unix/uxplink.c b/unix/uxplink.c index 186f3a6a..1dbf17c2 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -325,12 +325,13 @@ void cleanup_termios(void) bufchain stdout_data, stderr_data; enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; -int try_output(bool is_stderr) +size_t try_output(bool is_stderr) { bufchain *chain = (is_stderr ? &stderr_data : &stdout_data); int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO); void *senddata; - int sendlen, ret; + size_t sendlen; + ssize_t ret; if (bufchain_size(chain) > 0) { bool prev_nonblock = nonblock(fd); @@ -354,7 +355,8 @@ int try_output(bool is_stderr) return bufchain_size(&stdout_data) + bufchain_size(&stderr_data); } -static int plink_output(Seat *seat, bool is_stderr, const void *data, int len) +static size_t plink_output( + Seat *seat, bool is_stderr, const void *data, size_t len) { if (is_stderr) { bufchain_add(&stderr_data, data, len); diff --git a/unix/uxpty.c b/unix/uxpty.c index 47b5ef51..c632ecc6 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1310,7 +1310,8 @@ static void pty_free(Backend *be) static void pty_try_write(Pty *pty) { void *data; - int len, ret; + size_t len; + ssize_t ret; assert(pty->master_i >= 0); @@ -1348,7 +1349,7 @@ static void pty_try_write(Pty *pty) /* * Called to send data down the pty. */ -static int pty_send(Backend *be, const char *buf, int len) +static size_t pty_send(Backend *be, const char *buf, size_t len) { Pty *pty = container_of(be, Pty, backend); @@ -1393,7 +1394,7 @@ static void pty_close(Pty *pty) /* * Called to query the current socket sendability status. */ -static int pty_sendbuffer(Backend *be) +static size_t pty_sendbuffer(Backend *be) { /* Pty *pty = container_of(be, Pty, backend); */ return 0; @@ -1494,7 +1495,7 @@ static bool pty_sendok(Backend *be) return true; } -static void pty_unthrottle(Backend *be, int backlog) +static void pty_unthrottle(Backend *be, size_t backlog) { /* Pty *pty = container_of(be, Pty, backend); */ /* do nothing */ diff --git a/unix/uxser.c b/unix/uxser.c index ec287be7..a2055d81 100644 --- a/unix/uxser.c +++ b/unix/uxser.c @@ -23,7 +23,7 @@ struct Serial { LogContext *logctx; int fd; bool finished; - int inbufsize; + size_t inbufsize; bufchain output_data; Backend backend; }; @@ -423,7 +423,8 @@ static void serial_uxsel_setup(Serial *serial) static void serial_try_write(Serial *serial) { void *data; - int len, ret; + size_t len; + ssize_t ret; assert(serial->fd >= 0); @@ -450,7 +451,7 @@ static void serial_try_write(Serial *serial) /* * Called to send data down the serial connection. */ -static int serial_send(Backend *be, const char *buf, int len) +static size_t serial_send(Backend *be, const char *buf, size_t len) { Serial *serial = container_of(be, Serial, backend); @@ -466,7 +467,7 @@ static int serial_send(Backend *be, const char *buf, int len) /* * Called to query the current sendability status. */ -static int serial_sendbuffer(Backend *be) +static size_t serial_sendbuffer(Backend *be) { Serial *serial = container_of(be, Serial, backend); return bufchain_size(&serial->output_data); @@ -519,7 +520,7 @@ static bool serial_sendok(Backend *be) return true; } -static void serial_unthrottle(Backend *be, int backlog) +static void serial_unthrottle(Backend *be, size_t backlog) { Serial *serial = container_of(be, Serial, backend); serial->inbufsize = backlog; diff --git a/utils.c b/utils.c index c38eb916..dc5af50a 100644 --- a/utils.c +++ b/utils.c @@ -642,7 +642,7 @@ void bufchain_clear(bufchain *ch) ch->buffersize = 0; } -int bufchain_size(bufchain *ch) +size_t bufchain_size(bufchain *ch) { return ch->buffersize; } @@ -655,7 +655,7 @@ void bufchain_set_callback_inner( ch->ic = ic; } -void bufchain_add(bufchain *ch, const void *data, int len) +void bufchain_add(bufchain *ch, const void *data, size_t len) { const char *buf = (const char *)data; @@ -665,14 +665,14 @@ void bufchain_add(bufchain *ch, const void *data, int len) while (len > 0) { if (ch->tail && ch->tail->bufend < ch->tail->bufmax) { - int copylen = min(len, ch->tail->bufmax - ch->tail->bufend); + size_t copylen = min(len, ch->tail->bufmax - ch->tail->bufend); memcpy(ch->tail->bufend, buf, copylen); buf += copylen; len -= copylen; ch->tail->bufend += copylen; } if (len > 0) { - int grainlen = + size_t grainlen = max(sizeof(struct bufchain_granule) + len, BUFFER_MIN_GRANULE); struct bufchain_granule *newbuf; newbuf = smalloc(grainlen); @@ -692,7 +692,7 @@ void bufchain_add(bufchain *ch, const void *data, int len) ch->queue_idempotent_callback(ch->ic); } -void bufchain_consume(bufchain *ch, int len) +void bufchain_consume(bufchain *ch, size_t len) { struct bufchain_granule *tmp; @@ -714,13 +714,13 @@ void bufchain_consume(bufchain *ch, int len) } } -void bufchain_prefix(bufchain *ch, void **data, int *len) +void bufchain_prefix(bufchain *ch, void **data, size_t *len) { *len = ch->head->bufend - ch->head->bufpos; *data = ch->head->bufpos; } -void bufchain_fetch(bufchain *ch, void *data, int len) +void bufchain_fetch(bufchain *ch, void *data, size_t len) { struct bufchain_granule *tmp; char *data_c = (char *)data; @@ -742,13 +742,13 @@ void bufchain_fetch(bufchain *ch, void *data, int len) } } -void bufchain_fetch_consume(bufchain *ch, void *data, int len) +void bufchain_fetch_consume(bufchain *ch, void *data, size_t len) { bufchain_fetch(ch, data, len); bufchain_consume(ch, len); } -bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len) +bool bufchain_try_fetch_consume(bufchain *ch, void *data, size_t len) { if (ch->buffersize >= len) { bufchain_fetch_consume(ch, data, len); @@ -758,7 +758,7 @@ bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len) } } -int bufchain_fetch_consume_up_to(bufchain *ch, void *data, int len) +size_t bufchain_fetch_consume_up_to(bufchain *ch, void *data, size_t len) { if (len > ch->buffersize) len = ch->buffersize; @@ -774,10 +774,9 @@ int bufchain_fetch_consume_up_to(bufchain *ch, void *data, int len) * sequences. */ -void sanitise_term_data(bufchain *out, const void *vdata, int len) +void sanitise_term_data(bufchain *out, const void *vdata, size_t len) { const char *data = (const char *)vdata; - int i; /* * FIXME: this method of sanitisation is ASCII-centric. It would @@ -786,7 +785,7 @@ void sanitise_term_data(bufchain *out, const void *vdata, int len) * (not to mention knowing what character set it should interpret * the data as). */ - for (i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { if (data[i] == '\n') bufchain_add(out, "\r\n", 2); else if (data[i] >= ' ' && data[i] < 0x7F) diff --git a/windows/wincons.c b/windows/wincons.c index 48dd3c2e..997ebb5a 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -388,7 +388,7 @@ static void console_eventlog(LogPolicy *lp, const char *string) console_logging_error(lp, string); } -static void console_data_untrusted(HANDLE hout, const char *data, int len) +static void console_data_untrusted(HANDLE hout, const char *data, size_t len) { DWORD dummy; bufchain sanitised; @@ -465,7 +465,7 @@ int console_get_userpass_input(prompts_t *p) for (curr_prompt = 0; curr_prompt < p->n_prompts; curr_prompt++) { DWORD savemode, newmode; - int len; + size_t len; prompt_t *pr = p->prompts[curr_prompt]; GetConsoleMode(hin, &savemode); @@ -486,7 +486,7 @@ int console_get_userpass_input(prompts_t *p) if (!ReadFile(hin, pr->result + len, pr->resultsize - len - 1, &ret, NULL) || ret == 0) { - len = -1; + len = (size_t)-1; break; } len += ret; @@ -505,7 +505,7 @@ int console_get_userpass_input(prompts_t *p) WriteFile(hout, "\r\n", 2, &dummy, NULL); } - if (len < 0) { + if (len == (size_t)-1) { return 0; /* failure due to read error */ } diff --git a/windows/window.c b/windows/window.c index d43afb8a..65d8abf9 100644 --- a/windows/window.c +++ b/windows/window.c @@ -320,7 +320,8 @@ bool win_seat_get_window_pixel_size(Seat *seat, int *x, int *y) return true; } -static int win_seat_output(Seat *seat, bool is_stderr, const void *, int); +static size_t win_seat_output( + Seat *seat, bool is_stderr, const void *, size_t); static bool win_seat_eof(Seat *seat); static int win_seat_get_userpass_input( Seat *seat, prompts_t *p, bufchain *input); @@ -5784,8 +5785,8 @@ static void flip_full_screen() } } -static int win_seat_output(Seat *seat, bool is_stderr, - const void *data, int len) +static size_t win_seat_output(Seat *seat, bool is_stderr, + const void *data, size_t len) { return term_data(term, is_stderr, data, len); } diff --git a/windows/winhandl.c b/windows/winhandl.c index 0e2a66ea..e291e2cb 100644 --- a/windows/winhandl.c +++ b/windows/winhandl.c @@ -348,12 +348,12 @@ static DWORD WINAPI handle_output_threadfunc(void *param) static void handle_try_output(struct handle_output *ctx) { void *senddata; - int sendlen; + size_t sendlen; if (!ctx->busy && bufchain_size(&ctx->queued_data)) { bufchain_prefix(&ctx->queued_data, &senddata, &sendlen); ctx->buffer = senddata; - ctx->len = sendlen; + ctx->len = min(sendlen, ~(DWORD)0); SetEvent(ctx->ev_from_main); ctx->busy = true; } else if (!ctx->busy && bufchain_size(&ctx->queued_data) == 0 && @@ -515,7 +515,7 @@ struct handle *handle_add_foreign_event(HANDLE event, return h; } -int handle_write(struct handle *h, const void *data, int len) +size_t handle_write(struct handle *h, const void *data, size_t len) { assert(h->type == HT_OUTPUT); assert(h->u.o.outgoingeof == EOF_NO); @@ -702,13 +702,13 @@ void handle_got_event(HANDLE event) } } -void handle_unthrottle(struct handle *h, int backlog) +void handle_unthrottle(struct handle *h, size_t backlog) { assert(h->type == HT_INPUT); handle_throttle(&h->u.i, backlog); } -int handle_backlog(struct handle *h) +size_t handle_backlog(struct handle *h) { assert(h->type == HT_OUTPUT); return bufchain_size(&h->u.o.queued_data); diff --git a/windows/winhsock.c b/windows/winhsock.c index 0f5586f5..541a37b4 100644 --- a/windows/winhsock.c +++ b/windows/winhsock.c @@ -45,7 +45,8 @@ typedef struct HandleSocket { Socket sock; } HandleSocket; -static int handle_gotdata(struct handle *h, const void *data, int len, int err) +static size_t handle_gotdata( + struct handle *h, const void *data, size_t len, int err) { HandleSocket *hs = (HandleSocket *)handle_get_privdata(h); @@ -79,7 +80,8 @@ static int handle_gotdata(struct handle *h, const void *data, int len, int err) } } -static int handle_stderr(struct handle *h, const void *data, int len, int err) +static size_t handle_stderr( + struct handle *h, const void *data, size_t len, int err) { HandleSocket *hs = (HandleSocket *)handle_get_privdata(h); @@ -89,7 +91,7 @@ static int handle_stderr(struct handle *h, const void *data, int len, int err) return 0; } -static void handle_sentdata(struct handle *h, int new_backlog, int err) +static void handle_sentdata(struct handle *h, size_t new_backlog, int err) { HandleSocket *hs = (HandleSocket *)handle_get_privdata(h); @@ -130,14 +132,14 @@ static void sk_handle_close(Socket *s) sfree(hs); } -static int sk_handle_write(Socket *s, const void *data, int len) +static size_t sk_handle_write(Socket *s, const void *data, size_t len) { HandleSocket *hs = container_of(s, HandleSocket, sock); return handle_write(hs->send_h, data, len); } -static int sk_handle_write_oob(Socket *s, const void *data, int len) +static size_t sk_handle_write_oob(Socket *s, const void *data, size_t len) { /* * oob data is treated as inband; nasty, but nothing really @@ -163,7 +165,7 @@ static void handle_socket_unfreeze(void *hsv) { HandleSocket *hs = (HandleSocket *)hsv; void *data; - int len; + size_t len; /* * If we've been put into a state other than THAWING since the diff --git a/windows/winnet.c b/windows/winnet.c index b65e8d33..c7187a03 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -60,7 +60,7 @@ struct NetSocket { * notification while we were frozen */ bool localhost_only; /* for listening sockets */ char oobdata[1]; - int sending_oob; + size_t sending_oob; bool oobinline, nodelay, keepalive, privport; enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; SockAddr *addr; @@ -832,8 +832,8 @@ static void sk_net_flush(Socket *s) } static void sk_net_close(Socket *s); -static int sk_net_write(Socket *s, const void *data, int len); -static int sk_net_write_oob(Socket *s, const void *data, int len); +static size_t sk_net_write(Socket *s, const void *data, size_t len); +static size_t sk_net_write_oob(Socket *s, const void *data, size_t len); static void sk_net_write_eof(Socket *s); static void sk_net_set_frozen(Socket *s, bool is_frozen); static const char *sk_net_socket_error(Socket *s); @@ -1378,7 +1378,8 @@ void try_send(NetSocket *s) int nsent; DWORD err; void *data; - int len, urgentflag; + size_t len; + int urgentflag; if (s->sending_oob) { urgentflag = MSG_OOB; @@ -1388,6 +1389,7 @@ void try_send(NetSocket *s) urgentflag = 0; bufchain_prefix(&s->output_data, &data, &len); } + len = min(len, INT_MAX); /* WinSock send() takes an int */ nsent = p_send(s->s, data, len, urgentflag); noise_ultralight(NOISE_SOURCE_IOLEN, nsent); if (nsent <= 0) { @@ -1443,7 +1445,7 @@ void try_send(NetSocket *s) } } -static int sk_net_write(Socket *sock, const void *buf, int len) +static size_t sk_net_write(Socket *sock, const void *buf, size_t len) { NetSocket *s = container_of(sock, NetSocket, sock); @@ -1463,7 +1465,7 @@ static int sk_net_write(Socket *sock, const void *buf, int len) return bufchain_size(&s->output_data); } -static int sk_net_write_oob(Socket *sock, const void *buf, int len) +static size_t sk_net_write_oob(Socket *sock, const void *buf, size_t len) { NetSocket *s = container_of(sock, NetSocket, sock); diff --git a/windows/winplink.c b/windows/winplink.c index 3543808f..9076d4e6 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -61,7 +61,8 @@ static void plink_echoedit_update(Seat *seat, bool echo, bool edit) SetConsoleMode(inhandle, mode); } -static int plink_output(Seat *seat, bool is_stderr, const void *data, int len) +static size_t plink_output( + Seat *seat, bool is_stderr, const void *data, size_t len) { if (is_stderr) { handle_write(stderr_handle, data, len); @@ -205,7 +206,7 @@ char *do_select(SOCKET skt, bool startup) return NULL; } -int stdin_gotdata(struct handle *h, const void *data, int len, int err) +size_t stdin_gotdata(struct handle *h, const void *data, size_t len, int err) { if (err) { char buf[4096]; @@ -217,6 +218,7 @@ int stdin_gotdata(struct handle *h, const void *data, int len, int err) fprintf(stderr, "Unable to read from standard input: %s\n", buf); cleanup_exit(0); } + noise_ultralight(NOISE_SOURCE_IOLEN, len); if (backend_connected(backend)) { if (len > 0) { @@ -229,7 +231,7 @@ int stdin_gotdata(struct handle *h, const void *data, int len, int err) return 0; } -void stdouterr_sent(struct handle *h, int new_backlog, int err) +void stdouterr_sent(struct handle *h, size_t new_backlog, int err) { if (err) { char buf[4096]; diff --git a/windows/winser.c b/windows/winser.c index 4afd150b..b11fe581 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -40,8 +40,8 @@ static void serial_terminate(Serial *serial) } } -static int serial_gotdata( - struct handle *h, const void *data, int len, int err) +static size_t serial_gotdata( + struct handle *h, const void *data, size_t len, int err) { Serial *serial = (Serial *)handle_get_privdata(h); if (err || len == 0) { @@ -73,7 +73,7 @@ static int serial_gotdata( } } -static void serial_sentdata(struct handle *h, int new_backlog, int err) +static void serial_sentdata(struct handle *h, size_t new_backlog, int err) { Serial *serial = (Serial *)handle_get_privdata(h); if (err) { @@ -295,7 +295,7 @@ static void serial_reconfig(Backend *be, Conf *conf) /* * Called to send data down the serial connection. */ -static int serial_send(Backend *be, const char *buf, int len) +static size_t serial_send(Backend *be, const char *buf, size_t len) { Serial *serial = container_of(be, Serial, backend); @@ -309,7 +309,7 @@ static int serial_send(Backend *be, const char *buf, int len) /* * Called to query the current sendability status. */ -static int serial_sendbuffer(Backend *be) +static size_t serial_sendbuffer(Backend *be) { Serial *serial = container_of(be, Serial, backend); return serial->bufsize; @@ -386,7 +386,7 @@ static bool serial_sendok(Backend *be) return true; } -static void serial_unthrottle(Backend *be, int backlog) +static void serial_unthrottle(Backend *be, size_t backlog) { Serial *serial = container_of(be, Serial, backend); if (serial->in) diff --git a/windows/winstuff.h b/windows/winstuff.h index 5a1f13bf..c2da098b 100644 --- a/windows/winstuff.h +++ b/windows/winstuff.h @@ -603,21 +603,21 @@ void init_ucs(Conf *, struct unicode_data *); #define HANDLE_FLAG_IGNOREEOF 2 #define HANDLE_FLAG_UNITBUFFER 4 struct handle; -typedef int (*handle_inputfn_t)( - struct handle *h, const void *data, int len, int err); +typedef size_t (*handle_inputfn_t)( + struct handle *h, const void *data, size_t len, int err); typedef void (*handle_outputfn_t)( - struct handle *h, int new_backlog, int err); + struct handle *h, size_t new_backlog, int err); struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata, void *privdata, int flags); struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata, void *privdata, int flags); -int handle_write(struct handle *h, const void *data, int len); +size_t handle_write(struct handle *h, const void *data, size_t len); void handle_write_eof(struct handle *h); HANDLE *handle_get_events(int *nevents); void handle_free(struct handle *h); void handle_got_event(HANDLE event); -void handle_unthrottle(struct handle *h, int backlog); -int handle_backlog(struct handle *h); +void handle_unthrottle(struct handle *h, size_t backlog); +size_t handle_backlog(struct handle *h); void *handle_get_privdata(struct handle *h); struct handle *handle_add_foreign_event(HANDLE event, void (*callback)(void *), void *ctx); diff --git a/x11fwd.c b/x11fwd.c index d06e0869..91a5da75 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -726,7 +726,7 @@ static void x11_closing(Plug *plug, const char *error_msg, int error_code, } } -static void x11_receive(Plug *plug, int urgent, const char *data, int len) +static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) { struct X11Connection *xconn = container_of( plug, struct X11Connection, plug); @@ -735,7 +735,7 @@ static void x11_receive(Plug *plug, int urgent, const char *data, int len) sshfwd_write(xconn->c, data, len); } -static void x11_sent(Plug *plug, int bufsize) +static void x11_sent(Plug *plug, size_t bufsize) { struct X11Connection *xconn = container_of( plug, struct X11Connection, plug); @@ -770,7 +770,8 @@ static const PlugVtable X11Connection_plugvt = { }; static void x11_chan_free(Channel *chan); -static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len); +static size_t x11_send( + Channel *chan, bool is_stderr, const void *vdata, size_t len); static void x11_send_eof(Channel *chan); static void x11_set_input_wanted(Channel *chan, bool wanted); static char *x11_log_close_msg(Channel *chan); @@ -918,7 +919,8 @@ static bool x11_parse_ip(const char *addr_string, unsigned long *ip) /* * Called to send data down the raw connection. */ -static int x11_send(Channel *chan, bool is_stderr, const void *vdata, int len) +static size_t x11_send( + Channel *chan, bool is_stderr, const void *vdata, size_t len) { assert(chan->vt == &X11Connection_channelvt); X11Connection *xconn = container_of(chan, X11Connection, chan);