From: claudio Date: Sat, 18 Sep 2021 19:44:46 +0000 (+0000) Subject: check_send_expect() does some nasty ibuf magic to allow fn_match() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d2b99c18837c8c9128e1830308138b8a1d4f7b16;p=openbsd check_send_expect() does some nasty ibuf magic to allow fn_match() to work with a buffer that is not a real string. The wpos is decremented in the wrong spot and would affect both binary and non binary checks. Simplify this code by using strndup. OK rob@ benno@ --- diff --git a/usr.sbin/relayd/check_tcp.c b/usr.sbin/relayd/check_tcp.c index 0a92712c2df..6ab69526500 100644 --- a/usr.sbin/relayd/check_tcp.c +++ b/usr.sbin/relayd/check_tcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: check_tcp.c,v 1.57 2019/09/15 19:23:29 rob Exp $ */ +/* $OpenBSD: check_tcp.c,v 1.58 2021/09/18 19:44:46 claudio Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard @@ -321,23 +321,20 @@ check_send_expect(struct ctl_tcp_event *cte) /* * ensure string is nul-terminated. */ - b = ibuf_reserve(cte->buf, 1); + b = strndup(cte->buf->buf, ibuf_size(cte->buf)); if (b == NULL) fatal("out of memory"); - *b = '\0'; - if (fnmatch(cte->table->conf.exbuf, cte->buf->buf, 0) == 0) { + if (fnmatch(cte->table->conf.exbuf, b, 0) == 0) { cte->host->he = HCE_SEND_EXPECT_OK; cte->host->up = HOST_UP; + free(b); return (0); } + free(b); } + cte->host->he = HCE_SEND_EXPECT_FAIL; cte->host->up = HOST_UNKNOWN; - - /* - * go back to original position. - */ - cte->buf->wpos--; return (1); }