@@ -367,12 +367,9 @@ sshbuf_check_reserve(const struct sshbuf *buf, size_t len)
367367 if (buf -> readonly || buf -> refcount > 1 )
368368 return SSH_ERR_BUFFER_READ_ONLY ;
369369 SSHBUF_TELL ("check" );
370- /* Check that len is reasonable and that max size + available < len */
371- /* prior we'd check ((buf->max_size / 2) - len) */
372- /* cjr 4/17/24 */
373- if ((len > (buf -> max_size / 2 ) ||
374- ((buf -> max_size - len ) < (buf -> size - buf -> off ))))
375- return SSH_ERR_NO_BUFFER_SPACE ;
370+ /* Check that len is reasonable and that max_size + available < len */
371+ if (len > buf -> max_size || buf -> max_size - len < buf -> size - buf -> off )
372+ return SSH_ERR_NO_BUFFER_SPACE ;
376373 return 0 ;
377374}
378375
@@ -426,7 +423,7 @@ sshbuf_allocate(struct sshbuf *buf, size_t len)
426423 * Turns out the extra functions on the following conditional aren't needed
427424 * -cjr 04/06/23
428425 */
429- if (rlen > BUF_WATERSHED && buf -> type == BUF_CHANNEL_INPUT ) {
426+ if (rlen > BUF_WATERSHED ) { // && ( buf->type == BUF_CHANNEL_INPUT || buf->type == BUF_CHANNEL_OUTPUT) ) {
430427 /* debug_f ("Prior: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu", */
431428 /* buf->label, buf, rlen, need, buf->window_max, buf->max_size); */
432429 /* easiest thing to do is grow the nuffer by 4MB each time. It might end
@@ -436,14 +433,14 @@ sshbuf_allocate(struct sshbuf *buf, size_t len)
436433 /* debug_f ("Post: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu", */
437434 /* buf->label, buf, rlen, need, buf->window_max, buf->max_size); */
438435 }
439- if (rlen > BUF_WATERSHED && buf -> type == BUF_CHANNEL_OUTPUT ) {
440- / * debug_f ("Pre: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu", */
441- / * buf->label, buf, rlen, need, buf->window_max, buf->max_size); */
442- need = (4 * 1024 * 1024 );
443- rlen = ROUNDUP (buf -> alloc + need , SSHBUF_SIZE_INC );
444- / * debug_f ("Post: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu", */
445- / * buf->label, buf, rlen, need, buf->window_max, buf->max_size); */
446- }
436+ /* if (rlen > BUF_WATERSHED && buf->type == BUF_CHANNEL_OUTPUT) { */
437+ /* /\ * debug_f ("Pre: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu", *\/ */
438+ /* /\ * buf->label, buf, rlen, need, buf->window_max, buf->max_size); *\/ */
439+ /* need = (4*1024*1024); */
440+ /* rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC); */
441+ /* /\ * debug_f ("Post: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu", *\/ */
442+ /* /\ * buf->label, buf, rlen, need, buf->window_max, buf->max_size); *\/ */
443+ /* } */
447444 SSHBUF_DBG (("need %zu initial rlen %zu" , need , rlen ));
448445
449446 /* rlen might be above the max allocation */
0 commit comments