From b11b589f5b554e63bd124869c7a4b2a15f25b70a Mon Sep 17 00:00:00 2001 From: dtucker Date: Mon, 3 Apr 2023 08:10:54 +0000 Subject: [PATCH] Move null check up and simplify process_escapes. Based on Coverity CID 291863 which points out we check the channel pointer for NULLness after dereferencing it. Move this to the start of the function, and while there simplify initialization of efc a bit. ok djm@ --- usr.bin/ssh/clientloop.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c index 989d74921f4..67a9f173659 100644 --- a/usr.bin/ssh/clientloop.c +++ b/usr.bin/ssh/clientloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.391 2023/03/31 04:04:15 djm Exp $ */ +/* $OpenBSD: clientloop.c,v 1.392 2023/04/03 08:10:54 dtucker Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -996,14 +996,12 @@ process_escapes(struct ssh *ssh, Channel *c, u_int i; u_char ch; char *s; - struct escape_filter_ctx *efc = c->filter_ctx == NULL ? - NULL : (struct escape_filter_ctx *)c->filter_ctx; + struct escape_filter_ctx *efc; - if (c->filter_ctx == NULL) + if (c == NULL || c->filter_ctx == NULL || len <= 0) return 0; - if (len <= 0) - return (0); + efc = (struct escape_filter_ctx *)c->filter_ctx; for (i = 0; i < (u_int)len; i++) { /* Get one character at a time. */ @@ -1100,7 +1098,7 @@ process_escapes(struct ssh *ssh, Channel *c, continue; case '&': - if (c && c->ctl_chan != -1) + if (c->ctl_chan != -1) goto noescape; /* * Detach the program (continue to serve -- 2.20.1