1- /* $OpenBSD: channels.c,v 1.432 2023/07 /04 03:59:21 dlg Exp $ */
1+ /* $OpenBSD: channels.c,v 1.433 2023/09 /04 00:01:46 djm Exp $ */
22/*
33 * Author: Tatu Ylonen <[email protected] > 44 * Copyright (c) 1995 Tatu Ylonen <[email protected] >, Espoo, Finland @@ -2330,9 +2330,9 @@ channel_check_window(struct ssh *ssh, Channel *c)
23302330{
23312331 int r ;
23322332
2333- /* going back to a set denominator of 2. Prior versions had a
2334- * dynamic denominator based on the size of the buffer. This may
2335- * have been helpful in some situations but it isn't helping in
2333+ /* going back to a set denominator of 2. Prior versions had a
2334+ * dynamic denominator based on the size of the buffer. This may
2335+ * have been helpful in some situations but it isn't helping in
23362336 * the general case -cjr 6/30/23 */
23372337 if (c -> type == SSH_CHANNEL_OPEN &&
23382338 !(c -> flags & (CHAN_CLOSE_SENT |CHAN_CLOSE_RCVD )) &&
@@ -2944,8 +2944,9 @@ channel_after_poll(struct ssh *ssh, struct pollfd *pfd, u_int npfd)
29442944
29452945/*
29462946 * Enqueue data for channels with open or draining c->input.
2947+ * Returns non-zero if a packet was enqueued.
29472948 */
2948- static void
2949+ static int
29492950channel_output_poll_input_open (struct ssh * ssh , Channel * c )
29502951{
29512952 size_t len , plen ;
@@ -2966,7 +2967,7 @@ channel_output_poll_input_open(struct ssh *ssh, Channel *c)
29662967 else
29672968 chan_ibuf_empty (ssh , c );
29682969 }
2969- return ;
2970+ return 0 ;
29702971 }
29712972
29722973 if (!c -> have_remote_id )
@@ -2983,7 +2984,7 @@ channel_output_poll_input_open(struct ssh *ssh, Channel *c)
29832984 */
29842985 if (plen > c -> remote_window || plen > c -> remote_maxpacket ) {
29852986 debug ("channel %d: datagram too big" , c -> self );
2986- return ;
2987+ return 0 ;
29872988 }
29882989 /* Enqueue it */
29892990 if ((r = sshpkt_start (ssh , SSH2_MSG_CHANNEL_DATA )) != 0 ||
@@ -2992,6 +2993,7 @@ channel_output_poll_input_open(struct ssh *ssh, Channel *c)
29922993 (r = sshpkt_send (ssh )) != 0 )
29932994 fatal_fr (r , "channel %i: send datagram" , c -> self );
29942995 c -> remote_window -= plen ;
2996+ return 1 ;
29952997 }
29962998
29972999 /* Enqueue packet for buffered data. */
@@ -3000,7 +3002,7 @@ channel_output_poll_input_open(struct ssh *ssh, Channel *c)
30003002 if (len > c -> remote_maxpacket )
30013003 len = c -> remote_maxpacket ;
30023004 if (len == 0 )
3003- return ;
3005+ return 0 ;
30043006 if ((r = sshpkt_start (ssh , SSH2_MSG_CHANNEL_DATA )) != 0 ||
30053007 (r = sshpkt_put_u32 (ssh , c -> remote_id )) != 0 ||
30063008 (r = sshpkt_put_string (ssh , sshbuf_ptr (c -> input ), len )) != 0 ||
@@ -3009,19 +3011,21 @@ channel_output_poll_input_open(struct ssh *ssh, Channel *c)
30093011 if ((r = sshbuf_consume (c -> input , len )) != 0 )
30103012 fatal_fr (r , "channel %i: consume" , c -> self );
30113013 c -> remote_window -= len ;
3014+ return 1 ;
30123015}
30133016
30143017/*
30153018 * Enqueue data for channels with open c->extended in read mode.
3019+ * Returns non-zero if a packet was enqueued.
30163020 */
3017- static void
3021+ static int
30183022channel_output_poll_extended_read (struct ssh * ssh , Channel * c )
30193023{
30203024 size_t len ;
30213025 int r ;
30223026
30233027 if ((len = sshbuf_len (c -> extended )) == 0 )
3024- return ;
3028+ return 0 ;
30253029
30263030 debug2 ("channel %d: rwin %u elen %zu euse %d" , c -> self ,
30273031 c -> remote_window , sshbuf_len (c -> extended ), c -> extended_usage );
@@ -3030,7 +3034,7 @@ channel_output_poll_extended_read(struct ssh *ssh, Channel *c)
30303034 if (len > c -> remote_maxpacket )
30313035 len = c -> remote_maxpacket ;
30323036 if (len == 0 )
3033- return ;
3037+ return 0 ;
30343038 if (!c -> have_remote_id )
30353039 fatal_f ("channel %d: no remote id" , c -> self );
30363040 if ((r = sshpkt_start (ssh , SSH2_MSG_CHANNEL_EXTENDED_DATA )) != 0 ||
@@ -3043,15 +3047,20 @@ channel_output_poll_extended_read(struct ssh *ssh, Channel *c)
30433047 fatal_fr (r , "channel %i: consume" , c -> self );
30443048 c -> remote_window -= len ;
30453049 debug2 ("channel %d: sent ext data %zu" , c -> self , len );
3050+ return 1 ;
30463051}
30473052
3048- /* If there is data to send to the connection, enqueue some of it now. */
3049- void
3053+ /*
3054+ * If there is data to send to the connection, enqueue some of it now.
3055+ * Returns non-zero if data was enqueued.
3056+ */
3057+ int
30503058channel_output_poll (struct ssh * ssh )
30513059{
30523060 struct ssh_channels * sc = ssh -> chanctxt ;
30533061 Channel * c ;
30543062 u_int i ;
3063+ int ret = 0 ;
30553064
30563065 for (i = 0 ; i < sc -> channels_alloc ; i ++ ) {
30573066 c = sc -> channels [i ];
@@ -3074,12 +3083,13 @@ channel_output_poll(struct ssh *ssh)
30743083 /* Get the amount of buffered data for this channel. */
30753084 if (c -> istate == CHAN_INPUT_OPEN ||
30763085 c -> istate == CHAN_INPUT_WAIT_DRAIN )
3077- channel_output_poll_input_open (ssh , c );
3086+ ret |= channel_output_poll_input_open (ssh , c );
30783087 /* Send extended data, i.e. stderr */
30793088 if (!(c -> flags & CHAN_EOF_SENT ) &&
30803089 c -> extended_usage == CHAN_EXTENDED_READ )
3081- channel_output_poll_extended_read (ssh , c );
3090+ ret |= channel_output_poll_extended_read (ssh , c );
30823091 }
3092+ return ret ;
30833093}
30843094
30853095/* -- mux proxy support */
0 commit comments